New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't catch JsonStore IOErrors #5259
Comments
Just to note, regardless of the details of the issue, the ideal way to resolve this issue is to ask Android for the right external files dir. I think something like the following should work:
Even better, you can similarly get the external files directory that is dedicated to your application, does no require special permissions to write to, and will be cleared on uninstall. |
good to know; i think sdcard is generally safe but this would be ideal (my android uses 'emui' and for some reason its unbound the sdcard folder :/). ill investigate that as an alternative |
inclement's solution worked perfectly. saved me some processing power and some storage space. thanks |
@JellyWX could you please paste the path you got from
always worked for me. |
@KeyWeeUsr I believe it returned
My phone is a Huawei model, and when I added an SD card to the storage, for some reason the modified OS unbound the sdcard folder and made the /storage/6357-3031 folder. I have no idea why... but luckily the getExternalStorage works perfectly (unlike the JsonStore itself, it seems. I'm fighting with it as I type this) Sent from my HONOR BLN-L21 using FastHub |
Oh my... well, I've seen just slightly modified path (e.g. About JsonStore, I will try to look at it this weekend and see what's wrong with it. |
@KeyWeeUsr thanks :) I was looking at it myself before, but got sidetracked and couldn't nail some of the code used. I'm having some issues where the store only updates in memory it seems, but sometimes it works sometimes not. If i make a reproducible example I'll file a different issue for it Sent from my HONOR BLN-L21 using FastHub |
@JellyWX I can't really reproduce your issue. Pure The only error I get is when I actually try to put something into the storage, therefore when I do: j = JsonStore('somewhere')
j.put('something') # error here which throws an try:
j.put('something')
except:
pass which leads me to conclusion that you only tried to catch the error on a wrong place, which even appears to be true: try:
store = JsonStore('/sdcard/data.json') # no error here, nothing to catch
except:
try:
store = JsonStore('/storage/emulated/0/data.json')
except:
store = JsonStore('data.json')
# missing line for the example
store.put('whatever') # crash boom
|
ah, thanks for that :/ oh well 😅, i managed to work around the other one i
found, but it could be a feature :/ have to read the docs and produce some
minimal examples
On 22 Jul 2017 5:40 p.m., "Peter Badida" <notifications@github.com> wrote:
@JellyWX <https://github.com/jellywx> I can't really reproduce your issue.
Pure j = JsonStore('somewhere') doesn't trigger anything for me both on py2
and py3 with the latest stable (1.10.0).
The only error I get is when I actually try to put something into the
storage, therefore when I do:
j = JsonStore('somewhere')
j.put('something') # error here
which throws an IOError on Android for me and when I try to catch the
error, everything works just fine:
try:
j.put('something') except:
pass
which leads me to conclusion that you only tried to catch the error on a
wrong place, which even appears to be true:
try:
store = JsonStore('/sdcard/data.json') # no error here, nothing
to catchexcept:
try:
store = JsonStore('/storage/emulated/0/data.json')
except:
store = JsonStore('data.json')
# missing line for the example
store.put('whatever') # crash boom
# the same folder as the first "store" variable
I python : IOError: [Errno 2] No such file or directory: '/sdcard/data.json'
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5259 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AFUewk-oj1LUZjvMaUS5tQ8nR04XGWe0ks5sQiYQgaJpZM4OOkt7>
.
|
Versions
I'm trying to use a try loop to catch errors when kivy attempts to create JsonStores. This is necessary on Android, since not all phones have a proper
sdcard
folder, yet some do. However, JsonStore can't be caught with either a catch-all except or anIOError
specific exceptCode and Logs
yields:
The text was updated successfully, but these errors were encountered: