gpt4 book ai didi

python - httplib.InvalidURL : nonnumeric port:

转载 作者:太空狗 更新时间:2023-10-29 22:01:59 28 4
gpt4 key购买 nike

我正在尝试编写一个脚本来检查是否存在许多 url:

import httplib

with open('urls.txt') as urls:
for url in urls:
connection = httplib.HTTPConnection(url)
connection.request("GET")
response = connection.getresponse()
if response.status == 200:
print '[{}]: '.format(url), "Up!"

但是我得到了这个错误:

Traceback (most recent call last):
File "test.py", line 5, in <module>
connection = httplib.HTTPConnection(url)
File "/usr/lib/python2.7/httplib.py", line 693, in __init__
self._set_hostport(host, port)
File "/usr/lib/python2.7/httplib.py", line 721, in _set_hostport
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
httplib.InvalidURL: nonnumeric port: '//globo.com/galeria/amazonas/a.html

怎么了?

最佳答案

这可能是一个简单的解决方案,在这里

connection = httplib.HTTPConnection(url)

您正在使用 httpconnection,因此无需提供 url,例如 http://OSMQuote.com但是您需要提供 OSMQuote.com 而不是.

简而言之,从您的 URL 中删除 http://https://,因为 httplib 正在考虑 : 作为端口号,端口号必须是数字,

希望这对您有所帮助!

关于python - httplib.InvalidURL : nonnumeric port:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14491814/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com