question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Making requests to non-stadard port throws TimeoutError

See original GitHub issue

Python: 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
gabrielfalcaocommented, May 13, 2021

@ipetepete and @azurkin I’ll soon open a PR using your snippets as base.

2reactions
ipetepetecommented, Feb 12, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found