Invalid port number in request for secure site web page

David M. Cooke cookedm+news at physics.mcmaster.ca
Tue Oct 19 17:16:26 EDT 2004


"jfdutcher1958" <jfdutcher1958 at yahoo.com> writes:

> Python returns this message:
>
> InvalidURL: nonnumeric port: '//www.a2webhosting.com:2083/frontend/x2'
>
> in reponse to the call below ....but the port number looks 
> numeric  ???
>
> ***************************************************************
> import sys, httplib
> showlines = 56
> try:
>     servername, filename = sys.argv[1:]           # cmdline args?
> except:
>     servername, filename 
> = 'https://www.a2webhosting.com:2083/frontend/x2', '/index.html'
>     
> print servername, filename

You've forgotten a line (the one which throws the error you've given).
But, I believe your problem is 'https://www....' is parsed as a
server:port pair: the server is https, and the port is //www..., which
of course is invalid.

I presume you're doing httplib.HTTPConnection(servername) (or
HTTPSConnection). You can't use a URL there. Usage from the docs is
like this:
>>> h1 = httplib.HTTPConnection('www.cwi.nl')
>>> h2 = httplib.HTTPConnection('www.cwi.nl:80')
>>> h3 = httplib.HTTPConnection('www.cwi.nl', 80)

Depending on what you're doing, you might be better off using the
urllib or urllib2 modules.

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca



More information about the Python-list mailing list