This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author imrehg
Recipients imrehg
Date 2015-12-17.05:58:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1450331933.69.0.301225840177.issue25895@psf.upfronthosting.co.za>
In-reply-to
Content
Handling the "ws" and "wss" schemes of the WebSocket protocol in urllib.parse.urlparse was discussed in a previous issue http://bugs.python.org/issue13244 Parsing them seems to work correctly:

>>> urllib.parse.urlparse("wss://domain/endpoint")
ParseResult(scheme='wss', netloc='domain', path='/endpoint', params='', query='', fragment='')

On the other hand, urllib.parse.urljoin does not know about these schemes and thus cannot be used to construct WebSocket URLs (as, for example some streaming data APIs now seem to use it, such as https://starfighter.readme.io/docs/quotes-ticker-tape-websocket).

Using the example above I get:

>>> urllib.parse.urljoin("wss://domain/","/endpoint")
'/endpoint'

This is not the expected result, 'wss://example.com/endpoint', because these WebSocket schemes are not included in the uses_relative and uses_netloc lists in the library settings. For clarity, based on the previous issue's discussion and RFC6455 Section 11.1 https://tools.ietf.org/html/rfc6455#section-11.1 , these are the only two portions that apply, and should not be listed in uses_params.

As a workaround, similarly to the previous issue's recommendation, one can use:

>> import urlparse.parse
>> wsschemes = ["ws", "wss"]
>> urlparse.parse.uses_relative.extend(wsschemes)
>> urlparse.parse.uses_netloc.extend(wsschemes)

Attached patch to this effect. Also added tests to cover these schemes, though comments are definitely welcome on all of this!
History
Date User Action Args
2015-12-17 05:58:53imrehgsetrecipients: + imrehg
2015-12-17 05:58:53imrehgsetmessageid: <1450331933.69.0.301225840177.issue25895@psf.upfronthosting.co.za>
2015-12-17 05:58:53imrehglinkissue25895 messages
2015-12-17 05:58:52imrehgcreate