urllib2 having trouble processing colon symbol in url

Question:

I am using the API for challonge and their url format is https://username:[email protected]/api/.

However, when I use urllib2 in python to get this url

response = urllib2.urlopen('https://username:[email protected]/api/')

I get an error about a non-numerical port number. I believe this is caused by the colon (:) in the url making urllib2 think i’m trying to get a port of something.

Is there anyway around this issue, or am I doing something wrong?

Asked By: convergedtarkus

||

Answers:

This is because you must use auth handlers like urllib2.HTTPBasicAuthHandler or other.
urllib2 docs

Answered By: Denis
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.