3

I have two systems:

First one work as intended:

>>> urlparse.urlparse('foo://bar/?blu=1')
ParseResult(scheme='foo', netloc='bar', path='/', params='', query='blu=1', fragment='')

# sys.version_info(major=2, minor=7, micro=12, releaselevel='final', serial=0)

The second one does it different:

>>> urlparse.urlparse('foo://bar/?blu=1')
ParseResult(scheme='foo', netloc='bar', path='/?blu=1', params='', query='', fragment='')

#sys.version_info(major=2, minor=7, micro=3, releaselevel='final', serial=0)

What's wrong here?

Both use Python 2.7.

Stephen Docy
  • 4,738
  • 7
  • 18
  • 31
guettli
  • 25,042
  • 81
  • 346
  • 663
  • 5
    Can you please include the full Python version? `import sys; print sys.version_info` should give us enough. – Martijn Pieters Apr 12 '18 at 07:45
  • (Python 2.7 has seen a large number of updates and bugfixes over the years, this is almost certainly a version issue). – Martijn Pieters Apr 12 '18 at 07:46
  • 3
    Could be related to https://bugs.python.org/issue9374; based on the date that was closed I'd guess it's only in 2.7.7 and up. – jonrsharpe Apr 12 '18 at 07:48
  • With respect to the [RFC 1808](https://tools.ietf.org/html/rfc1808.html), this is definitely a bug, be sure to check that you have the latest Python 2.7 – Adonis Apr 12 '18 at 07:50
  • I get the first behavior with `2.7.14.final0`. – Graipher Apr 12 '18 at 07:54
  • @jonrsharpe: it was a fix that landed in [2.7.4rc1](https://raw.githubusercontent.com/python/cpython/2.7/Misc/NEWS.d/2.7.4rc1.rst). – Martijn Pieters Apr 12 '18 at 08:01
  • I added the needed version numbers. But one question remains: Whats wrong with this question? Why does it get down-voted? – guettli Apr 13 '18 at 11:10

1 Answers1

9

The second machine is running a very ancient Python 2.7 release. You have run into issue 9374, a fix for which landed in Python 2.7.4rc1, which released on 2013-03-23, so it's a 2.7 release older than that.

From the 2.7.4rc1 NEWS file:

  • Issue #9374: Generic parsing of query and fragment portions of url for any scheme. Supported both by RFC3986 and RFC2396.

The patch that fixes it is not that big, you could just copy the fixed urlsplit() function and monkey patch urllib with that if you can't upgrade that machine (you'll have to import some _private names from urllib first, of course).

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343