Python requests returns âcannot connect to proxy & error 10061â
<p>I have developed a desktop client using PyQt4, it connect to my web service by <a href="http://www.python-requests.org/en/master/" rel="nofollow">requests</a> lib. You know, <a href="http://www.python-requests.org/en/master/" rel="nofollow">requests</a> maybe one of the most useful http client, I think it should be no problem. My desktop client works all right until something strange happened. </p>

<p>I use the following code to send request to my server.</p>

<pre><code>response = requests.get(url, headers = self.getHeaders(), timeout=600, proxies = {}, verify = False)
</code></pre>

<p>where header only includes auth token.</p>

<pre><code> def getHeaders(self, additional = None):
    headers = {
               'Auth-Token' : HttpBasicClient.UserAuthToken,
               }
    if additional is not None:
        headers.update(additional)
    return headers
</code></pre>

<p>I cannot connect to my web service, all the http request pop the same error "'Cannot connect to proxy.', error(10061, '')". For example:</p>

<blockquote>
  <p>GET Url: http://  api.fangcloud.com/api/v1/user/timestamp
  HTTPSConnectionPool(host='api.fangcloud.com', port=443): Max retries exceeded with url: /api/v1/user/timestamp (Caused by ProxyError('Cannot connect to proxy.', error(10061, '')))</p>
</blockquote>

<p>this API does nothing but return the timestamp of my server. When I copy the url into Chrome in same machine with same environment, it returns correct response. However, my desktop client can only returns error. Is it anything wrong with requests lib?</p>

<p>I googled this problem of connection error 10061 ("No connection could be made because the target machine actively refused it"). This maybe caused by TCP connect rejection of web server.</p>

<blockquote>
  <p>The client sends a SYN packet to the server targeting the port (80 for HTTP). A server that is running a service on port 80 will respond with a SYN ACK, but if it is not, it will respond with a RST ACK. Your client reaches the server, but not the intended service. This is one way a server could âactively refuseâ a connection attempt.</p>
</blockquote>

<p>But why? My client works all right before and Chrome still works. I use no proxy on my machine. Is there anything I miss?</p>

<p>I notice there is a white space in URL, is that correct?
I tested in my ipython with requests.. that the response was:</p>

<pre><code>{
   "timestamp": 1472760770,
   "success": true
}
</code></pre>

<p>For HTTP and HTTPS.</p>

python tcp connection python-requests