Python:Urllib.urlopen 非数字端口
对于以下代码,
theurl = "https://%s:%[email protected]/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:])
有什么想法吗???
for the following code
theurl = "https://%s:%[email protected]/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
i get the following error
File "c:\Python31\lib\http\client.py", line 667, in _set_hostport
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
Any Ideas???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能需要对密码进行 url 编码。如果密码恰好包含“/”,您将看到类似的错误。
这是一个本地示例(实际值已编辑):
对密码进行编码:
您可以使用 urllib.quote('somepass/a', safe='') 进行编码。
You probably need to url-encode the password. You'll see an error like that if the password happens to contain a '/'.
Here's a local example (actual values redacted):
Encode the password:
You can use
urllib.quote('somepass/a', safe='')
to do the encoding.我同意muckabout,这就是问题所在。
您可能习惯在浏览器中使用它,这将导致浏览器向主机进行身份验证。您可能应该删除第一个@符号之前的所有内容。
查看 urllib 文档,特别是 FancyURLOpener,它可能会解决您的身份验证问题。
I agree with muckabout, this is the problem.
You're probably used to using this in a browser, which would cause the browser to authenticate with the host. You should probably drop everything before the first @ sign.
have a look at urllib docs, specifically FancyURLOpener which might resolve your issue with authentication.
该错误消息表明您正在准备的网址存在一些问题。打印并检查这是否是有效的网址。
The error message shows that there is some issue with the url that you are preparing. Print and check if this is a valid url.
假定 HTTP URL 中的“:”位于端口号之前。您输入的帐户名称不是数字。它必须是整数端口值。
The ':' in the HTTP URL is assumed to precede a port number. You are placing an account name which is not numeric. It must be an integer port value.