requests.exceptions.ConnectionError:HTTPConnectionPool

MLSC

我有一个像这样的python脚本:

#!/usr/bin/python
import sys
import requests

if len(sys.argv) < 2:
        print 'usage: python %s <file-urls>' % (sys.argv[0])
        sys.exit(2)

print '%-15s %20s' % ('URL_PAGE', 'STATUS')

FileName = sys.argv[1]
InputFile = open(FileName)
OK = open('ok.txt', 'w+')
NOK = open('nok.txt', 'w+')
for url in InputFile:
    status = requests.get(url).status_code
    print '%-15s %15s' % (url.strip(), status)
    if status == 200:
        OK.write('%-15s %15s' % (url.strip(), status) + '\n')
        OK.flush()
    else:
        NOK.write('%-15s %15s' % (url.strip(), status) + '\n')
        NOK.flush()
OK.close()
NOK.close()

当我运行它时,出现以下错误提示:

Traceback (most recent call last):
  File "url-code.py", line 18, in <module>
    status = requests.get(url).status_code
  File "/usr/lib/python2.7/dist-packages/requests/api.py", line 55, in get
    return request('get', url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 383, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 486, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 378, in send
    raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='google.com%0A', port=80): Max retries exceeded with url: / (Caused by <class 'socket.gaierror'>: [Errno -2] Name or service not known)

它是什么?我该如何处理并解决它?

马丁·彼得斯(Martijn Pieters)

您的中有换行符urlASCII码点0A是\n换行符。

剥去您的输入行:

for url in InputFile:
    url = url.strip()

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

requests.exceptions.ConnectionError:HTTPConnectionPool

来自分类Dev

“ requests.exceptions.ConnectionError :('连接被中止。,RemoteDisconnected('远端封闭的无响应的连接',))”

来自分类Dev

requests.exceptions.ConnectionError: ('Connection aborted.', error(2, 'No such file or directory'))

来自分类Dev

requests.exceptions.ChunkedEncodingError 连接中断

来自分类Dev

是什么原因导致“ elasticsearch.exceptions.ConnectionError:ConnectionError ...错误('getaddrinfo()参数2必须为整数或字符串',)))

来自分类Dev

Python request.exceptions.ConnectionError:HTTPSConnectionPool:URL超过最大重试次数:[Errno 111]连接被拒绝)

来自分类Dev

redis.exceptions.ConnectionError:错误-2连接到localhost:6379。名称或服务未知

来自分类Dev

对于循环抓取网站,网站会出现timeouterror,newconnectionerror和request.exceptions.ConnectionError

来自分类Dev

requests.exceptions.SSLError:HTTPSConnectionPool(host ='api-fxpractice.oanda.com',port = 443):URL超过了最大重试次数

来自分类Dev

Python HTTPConnectionPool 错误

来自分类Dev

elasticsearch异常ConnectionError

来自分类Dev

Python请求ConnectionError

来自分类Dev

Testing Exceptions with Nunit

来自分类Dev

Catching exceptions in destructors

来自分类Dev

Using RAII to nest exceptions

来自分类Dev

Programmatically distinguish exceptions

来自分类Dev

gspread.exceptions.SpreadsheetNotFound

来自分类Dev

BOOST_NO_EXCEPTIONS是否保证与-fno-exceptions兼容?

来自分类Dev

使用pip时出现ConnectionError

来自分类Dev

使用pip时出现ConnectionError

来自分类Dev

django.core.exceptions.ImproperlyConfigured

来自分类Dev

Django.core.exceptions.ImproperlyConfigured:

来自分类Dev

ctypes <类型'exceptions.TypeError'>

来自分类Dev

需要捕获IOExceptions和Exceptions

来自分类Dev

django.urls.exceptions.NoReverseMatch:

来自分类Dev

基本的Python:exceptions.NameError

来自分类Dev

Django.core.exceptions.ImproperlyConfigured:

来自分类Dev

jinja2.exceptions.TemplateSyntaxError

来自分类Dev

Implementing TFS Pull Requests

Related 相关文章

  1. 1

    requests.exceptions.ConnectionError:HTTPConnectionPool

  2. 2

    “ requests.exceptions.ConnectionError :('连接被中止。,RemoteDisconnected('远端封闭的无响应的连接',))”

  3. 3

    requests.exceptions.ConnectionError: ('Connection aborted.', error(2, 'No such file or directory'))

  4. 4

    requests.exceptions.ChunkedEncodingError 连接中断

  5. 5

    是什么原因导致“ elasticsearch.exceptions.ConnectionError:ConnectionError ...错误('getaddrinfo()参数2必须为整数或字符串',)))

  6. 6

    Python request.exceptions.ConnectionError:HTTPSConnectionPool:URL超过最大重试次数:[Errno 111]连接被拒绝)

  7. 7

    redis.exceptions.ConnectionError:错误-2连接到localhost:6379。名称或服务未知

  8. 8

    对于循环抓取网站,网站会出现timeouterror,newconnectionerror和request.exceptions.ConnectionError

  9. 9

    requests.exceptions.SSLError:HTTPSConnectionPool(host ='api-fxpractice.oanda.com',port = 443):URL超过了最大重试次数

  10. 10

    Python HTTPConnectionPool 错误

  11. 11

    elasticsearch异常ConnectionError

  12. 12

    Python请求ConnectionError

  13. 13

    Testing Exceptions with Nunit

  14. 14

    Catching exceptions in destructors

  15. 15

    Using RAII to nest exceptions

  16. 16

    Programmatically distinguish exceptions

  17. 17

    gspread.exceptions.SpreadsheetNotFound

  18. 18

    BOOST_NO_EXCEPTIONS是否保证与-fno-exceptions兼容?

  19. 19

    使用pip时出现ConnectionError

  20. 20

    使用pip时出现ConnectionError

  21. 21

    django.core.exceptions.ImproperlyConfigured

  22. 22

    Django.core.exceptions.ImproperlyConfigured:

  23. 23

    ctypes <类型'exceptions.TypeError'>

  24. 24

    需要捕获IOExceptions和Exceptions

  25. 25

    django.urls.exceptions.NoReverseMatch:

  26. 26

    基本的Python:exceptions.NameError

  27. 27

    Django.core.exceptions.ImproperlyConfigured:

  28. 28

    jinja2.exceptions.TemplateSyntaxError

  29. 29

    Implementing TFS Pull Requests

热门标签

归档