对于以下代码
theurl = "https://%s:%[email protected] /cdn-cgi/l/email-protection/nic/update?hostname=%s&myip=%s&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG" % (username, password, hostname, theip)
conn = urlopen(theurl) # send the request to the url
print(conn.read()) # read the response
conn.close() # close the connection
我收到以下错误
File "c:\Python31\lib\http\client.py", line 667, in _set_hostport
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
有任何想法吗???
您可能需要对密码进行 url 编码。如果密码恰好包含“/”,您将看到类似的错误。
这是一个本地示例(实际值已编辑):
>>> opener
<urllib.FancyURLopener instance at 0xb6f0e2ac>
>>> opener.open('http://admin:[email protected] /cdn-cgi/l/email-protection')
<addinfourl at 3068618924L whose fp = <socket._fileobject object at 0xb6e7596c>>
>>> opener.open('http://admin:somepass/[email protected] /cdn-cgi/l/email-protection')
*** InvalidURL: nonnumeric port: 'somepass'
对密码进行编码:
>>> opener.open('http://admin:somepass%[email protected] /cdn-cgi/l/email-protection')
您可以使用urllib.quote('somepass/a', safe='')
进行编码。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)