Making requests to non-stadard port throws TimeoutError
See original GitHub issuePython: 3.8.0 httpretty: 0.9.7
What I tried:
import httpretty
import requests
httpretty.register_uri(httpretty.GET, 'http://fakeuri.com:8080', body='{"hello":"world"}')
req = requests.get('http://fakeuri.com:8080')
What I expected:
req.status = 200
req.json() ={"hello":"world"}
What I got:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/local/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/usr/local/lib/python3.6/http/client.py", line 986, in send
self.sock.sendall(data)
File "/usr/local/lib/python3.6/site-packages/httpretty/core.py", line 554, in sendall
self.real_sendall(data)
File "/usr/local/lib/python3.6/site-packages/httpretty/core.py", line 474, in real_sendall
sock.connect(self._address)
TimeoutError: [Errno 110] Connection timed out
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Why do I receive a timeout error from Pythons requests module?
hi tk u for quick reply. this is a better answer because Catching this error will catch both ConnectTimeout and ReadTimeout errors. – ......
Read more >Connection raises TimeoutError, but IB gateway is running ...
I experienced this error myself, and the linux command sudo ss -tulpn showed the API port being hogged by a an old TWS...
Read more >Timeout in Python requests – Everything you need to know
Once a timeout value has been set, every request that doesn't receive a response in the specified timeframe will raise a Timeout error....
Read more >TimeoutException Class (System) - Microsoft Learn
The exception that is thrown when the time allotted for a process or operation has expired.
Read more >Connection Timeout vs. Read Timeout for Java Sockets
Sometimes, firewalls block certain ports due to security reasons. As a result, a “connection timed out” error can occur when a client is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ipetepete and @azurkin I’ll soon open a PR using your snippets as base.
I thought about that after I made the pull request. Feels wrong to have a warning/caveat to usage in that manner.
I have tried the following regex and it works:
re.search(r'^\w+://[^/]+[.]\w{2,}(:[0-9]+)?$', uri)
But unfortunately I can’t get the tests to run using virtualenv and I get errors in pipenv, probably because my python version is 3.8.7…idk, but I can’t chase that down right now. I’ll submit a pull request with the new regex once I have time to fiddle with running the tests.