Skip to content

Fix urlretrieve issue on python2 #332

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

Merged
merged 6 commits into from
Jan 31, 2019
Merged

Conversation

hackalog
Copy link
Contributor

@hackalog hackalog commented Jan 9, 2019

Occasionally, when calling urlretrieve() on a url, a strange error is seen (#322) about a missing readinto. I think this is a bug in python-future (PythonCharmers/python-future#423) on Python 2. In the meantime, my workaround is to require and use the requests module in kivy-ios in this failure case.

While here, incorporate @Jonast's retry idea proposed in kivy/python-for-android#1574

@ghost
Copy link

ghost commented Jan 10, 2019

I'm not involved with kivy-ios, but it would probably be helpful to explain why you are moving certain files to another location. Also, catching all exceptions from urlretrieve seems like overkill at least to me - it might be preferable to investigate why you're actually getting this AttributeError because it seems like a requests or stdlib bug that should probably be fixed at the right location

@hackalog
Copy link
Contributor Author

The file moves are because this diff is build on top of #331 (required to even get to the point where this bug is triggered), and so those parts will go away if and when #331 is is merged (and can be ignored for now).

The bug being addressed is the code path that leads to the upstream bug in python-future, which is getting invoked here. I see no easy fix unless upstream accepts PythonCharmers/python-future#423

That being said, I should mark this a work in progress, at least for now

@hackalog hackalog changed the title Fix urlretrieve issue on python2 [WIP] Fix urlretrieve issue on python2 Jan 10, 2019
@ghost
Copy link

ghost commented Jan 10, 2019

@hackalog ah, but if it's such a specific known issue then you should definitely just catch AttributeError, and only if Python 2 is used! (check with sys.version_info.major) Also I highly recommend adding a code comment to that except clause which links the bug you referenced. Otherwise, everyone will forget why on earth this code is catching an AttributeError and when that could ever be possibly removed (assuming upstream ever fixes it)

@hackalog
Copy link
Contributor Author

Those suggestions are all legit. I had originally thought a drop-in one line replacement of requests for urlretrieve would do the trick, but FTP reared its ugly head.

Let me work this up into a less heavy-handed form.

@ghost
Copy link

ghost commented Jan 10, 2019

that looks like a nice combination 😄 I like how it looks like now

@hackalog
Copy link
Contributor Author

Yes, thanks for the feedback @Jonast . As far as crude workarounds go, it's looking almost forgivable now. :)

@hackalog hackalog changed the title [WIP] Fix urlretrieve issue on python2 Fix urlretrieve issue on python2 Jan 10, 2019
FancyUrlopener.urlretrieve was failing on redirect, but in an insidious way, because of a bug in the python-future module:
PythonCharmers/python-future#425
Replace with the requests module for the time being.
try:
from pbxproj import XcodeProject
from pbxproj.pbxextensions.ProjectFiles import FileOptions
except ImportError:
print("ERROR: pbxproj requirements is missing")
print("ERROR: Python requirements are missing")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why changing this? Should i just say "missing pbxproj" instead?
The rest is good, but i don't understand this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, an interim version of the fix added the requests import here, so there were 2 packages being imported (learnleapfly@999dc68#diff-c3327fdae2ebcc6a34dc5a9d23ae9ffd) I neglected to change it back (sort of figuring more things might end up in requirements.txt before long)

@hackalog
Copy link
Contributor Author

@tito would you like me to change that Python->pbxproj string back, or does this look good to merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants