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
Bug in python >= 2.7 with urllib2 fragment #55912
Comments
result = urllib.urlopen("http://docs.python.org/library/urllib.html#OK")
print result.geturl()
result = urllib2.urlopen("http://docs.python.org/library/urllib.html#OK")
print result.geturl() Python 2.6 returns: Python 2.7 returns: 2to3 -w test.py I expect geturl() result with "#OK" in all cases |
This is because the Request class' constructor splits the URL into __original and fragment: def __init__(self, url, data=None, headers={},
origin_req_host=None, unverifiable=False):
# unwrap('<URL:type://host/path>') --> 'type://host/path'
self.__original = unwrap(url)
self.__original, fragment = splittag(self.__original) And the construction of object that urlopen() returns has its geturl() returns the request object's __original field (by now, minus the fragment). |
Attaching patches against 2.7 and 3.1 branches. |
Santa4nt, I think you also need to check case with Redirect Response URL: print urllib2.urlopen("http://16.foobnix-cms.appspot.com/test_base").geturl() python 2.6 returns OK python 2.7 returns KO |
It already does. ;-) Python 2.7.1+ (default, Apr 6 2011, 16:25:38) [MSC v.1500 32 bit (Intel)] on wi
n32
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib2
[74578 refs]
>>> fp = urllib2.urlopen('http://16.foobnix-cms.appspot.com/test_base')
[75643 refs]
>>> fp.geturl()
"http://16.foobnix-cms.appspot.com/test_redirect#json={value:'OK'}"
[75645 refs] I'm attaching patches with the appropriate unittest for the redirected case, though. |
New changeset 3f240a1cd245 by Senthil Kumaran in branch '3.1': |
It should be noted that the bug surfaced in 2.7 and above due to changes made as part of bpo-8280. |
New changeset 6e73f75ee034 by Senthil Kumaran in branch '2.7': |
This is fixed in all the codelines. Thanks for the patch, Santoso. |
New changeset 8ee48ec69844 by Senthil Kumaran in branch '3.1': |
New changeset 502bb809b03b by Senthil Kumaran in branch '2.7': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: