Skip to content
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

urllib2 passes fragment identifier to server #52527

Closed
methane opened this issue Apr 1, 2010 · 4 comments
Closed

urllib2 passes fragment identifier to server #52527

methane opened this issue Apr 1, 2010 · 4 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@methane
Copy link
Member

methane commented Apr 1, 2010

BPO 8280
Nosy @orsenthil, @merwok, @methane
Files
  • fragment.patch
  • 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:

    assignee = 'https://github.com/orsenthil'
    closed_at = <Date 2010-08-08.11:47:46.183>
    created_at = <Date 2010-04-01.16:08:31.765>
    labels = ['type-bug', 'library']
    title = 'urllib2 passes fragment identifier to server'
    updated_at = <Date 2010-08-08.11:47:46.182>
    user = 'https://github.com/methane'

    bugs.python.org fields:

    activity = <Date 2010-08-08.11:47:46.182>
    actor = 'orsenthil'
    assignee = 'orsenthil'
    closed = True
    closed_date = <Date 2010-08-08.11:47:46.183>
    closer = 'orsenthil'
    components = ['Library (Lib)']
    creation = <Date 2010-04-01.16:08:31.765>
    creator = 'methane'
    dependencies = []
    files = ['18358']
    hgrepos = []
    issue_num = 8280
    keywords = ['patch']
    message_count = 4.0
    messages = ['102103', '112712', '112721', '113250']
    nosy_count = 4.0
    nosy_names = ['orsenthil', 'dstanek', 'eric.araujo', 'methane']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue8280'
    versions = ['Python 2.6', 'Python 3.1', 'Python 2.7', 'Python 3.2']

    @methane
    Copy link
    Member Author

    methane commented Apr 1, 2010

    >>> urllib2.urlopen("http://wave-robot-python-client.googlecode.com/svn/trunk/pydocs/index.html#module-wavelet")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\usr\Python2.6\lib\urllib2.py", line 126, in urlopen
        return _opener.open(url, data, timeout)
      File "C:\usr\Python2.6\lib\urllib2.py", line 398, in open
        response = meth(req, response)
      File "C:\usr\Python2.6\lib\urllib2.py", line 511, in http_response
        'http', request, response, code, msg, hdrs)
      File "C:\usr\Python2.6\lib\urllib2.py", line 436, in error
        return self._call_chain(*args)
      File "C:\usr\Python2.6\lib\urllib2.py", line 370, in _call_chain
        result = func(*args)
      File "C:\usr\Python2.6\lib\urllib2.py", line 519, in http_error_default
        raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
    urllib2.HTTPError: HTTP Error 400: Bad Request

    This happens when redirected URL contains fragment.

    >>> urllib2.urlopen("http://goo.gl/z1d5")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\usr\Python2.6\lib\urllib2.py", line 126, in urlopen
        return _opener.open(url, data, timeout)
      File "C:\usr\Python2.6\lib\urllib2.py", line 398, in open
        response = meth(req, response)
      File "C:\usr\Python2.6\lib\urllib2.py", line 511, in http_response
        'http', request, response, code, msg, hdrs)
      File "C:\usr\Python2.6\lib\urllib2.py", line 430, in error
        result = self._call_chain(*args)
      File "C:\usr\Python2.6\lib\urllib2.py", line 370, in _call_chain
        result = func(*args)
      File "C:\usr\Python2.6\lib\urllib2.py", line 606, in http_error_302
        return self.parent.open(new, timeout=req.timeout)
      File "C:\usr\Python2.6\lib\urllib2.py", line 398, in open
        response = meth(req, response)
      File "C:\usr\Python2.6\lib\urllib2.py", line 511, in http_response
        'http', request, response, code, msg, hdrs)
      File "C:\usr\Python2.6\lib\urllib2.py", line 436, in error
        return self._call_chain(*args)
      File "C:\usr\Python2.6\lib\urllib2.py", line 370, in _call_chain
        result = func(*args)
      File "C:\usr\Python2.6\lib\urllib2.py", line 519, in http_error_default
        raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
    urllib2.HTTPError: HTTP Error 400: Bad Request

    urllib2.Request.get_selector() should be:

        def get_selector(self):
            return self.__r_host.split('#')[0]

    @methane methane added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 1, 2010
    @orsenthil orsenthil self-assigned this Apr 6, 2010
    @dstanek
    Copy link
    Mannequin

    dstanek mannequin commented Aug 3, 2010

    Added a patch to fix this behavior.

    @dstanek
    Copy link
    Mannequin

    dstanek mannequin commented Aug 3, 2010

    I have also uploaded my patch to http://codereview.appspot.com/1918042 so easier viewing.

    @orsenthil
    Copy link
    Member

    Fixed in revision 83818(py3k), 83819 (release31-maint) and 83820 (release27-maint).

    David, a couple of comments on your patch.

    • Request method was from urllib2, so the proper place of tests were test_urllib2. This already had Requests test so some additional tests were only required.
    • Also, now the fragments are removed and sent to the server, a proper response could be obtained, it can tested via 'network' tests in test_urllib2net.

    You might check the svn diffs to see the changes made.
    Thanks for the patch.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants