Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requests timeout not working as expected #4790

Closed
garg10may opened this issue Sep 14, 2018 · 2 comments
Closed

Requests timeout not working as expected #4790

garg10may opened this issue Sep 14, 2018 · 2 comments

Comments

@garg10may
Copy link

garg10may commented Sep 14, 2018

Please refer to our Stack Overflow tag for guidance.
requests.get('http://www.google.co.in', timeout=0.001)

Using above on one server works fine but on another server where probably outside access is not allowed requests doesn't timeout the request and only fails after few seconds with below error.

Traceback (most recent call last):
  File "/home/utrade/utradeENV/lib/python3.6/site-packages/urllib3/connection.py", line 141, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/home/utrade/utradeENV/lib/python3.6/site-packages/urllib3/util/connection.py", line 60, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/home/utrade/python3.6_optimized/lib/python3.6/socket.py", line 743, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/utrade/utradeENV/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/home/utrade/utradeENV/lib/python3.6/site-packages/urllib3/connectionpool.py", line 356, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/home/utrade/python3.6_optimized/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/home/utrade/python3.6_optimized/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/home/utrade/python3.6_optimized/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/home/utrade/python3.6_optimized/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/home/utrade/python3.6_optimized/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/home/utrade/utradeENV/lib/python3.6/site-packages/urllib3/connection.py", line 166, in connect
    conn = self._new_conn()
  File "/home/utrade/utradeENV/lib/python3.6/site-packages/urllib3/connection.py", line 150, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f9342c32f98>: Failed to establish a new connection: [Errno -2] Name or service
 not known

What am I doing wrong or how can I make it timeout?

@sethmlarson
Copy link
Member

This is because name resolution doesn't take the timeout into account. This is a lower-level issue than requests, see urllib3/urllib3#1334.

@garg10may
Copy link
Author

ok, thanks. I will try using python signal.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants