0
votes

I have developed a desktop client using PyQt4, it connect to my web service by requests lib. You know, requests 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.

I use the following code to send request to my server.

response = requests.get(url, headers = self.getHeaders(), timeout=600, proxies = {}, verify = False)

where header only includes auth token.

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

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

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, '')))

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?

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.

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.

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

1
share the python code - Nabeel Ahmed
mainly 10061 comes from the OS (not Python) - but your mention of api working fine from browser is something to look into. did you test it using from the same system ? and same request params ? - Nabeel Ahmed
Yep, I use Postman (the http client plugin of Chrome), fill the same params, it works all right too. Is this because OS security strategy? - L. RJ
are you using any proxy ? if not try it without the empty proxies = {} param, and also try it using urlib2 - to get to the issue - Nabeel Ahmed

1 Answers

0
votes

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

{
   "timestamp": 1472760770,
   "success": true
}

For HTTP and HTTPS.