as3rdaccount
as3rdaccount

Reputation: 3951

urllib does not handle # character properly

I have my url that looks like as follows:

http://me:me1234#@localhost:8080/

When I run urlparse on this url, instead of the netlocpath returning me:me1234#@localhost:8080 it only returns me:me1234.

from six.moves.urllib import parse
o=parse.urlparse('http://me:me1234#@localhost:8080/')
print o

ParseResult(scheme='http', netloc='me:me1234', path='', params='', query='', fragment='@localhost:8080/')

Any idea how why it is failing to parse #? I think this is a pretty standard url.

Upvotes: 0

Views: 71

Answers (1)

tynn
tynn

Reputation: 39853

It's a fragment. You need to encode it first:

from six.moves.urllib import parse
o=parse.urlparse('http://me:me1234%23@localhost:8080/')
print o

This should work for your needs.

Upvotes: 1

Related Questions