pipreqs icon indicating copy to clipboard operation
pipreqs copied to clipboard

add an argument specifying requests timeout to avoid hanging forever

Open sify21 opened this issue 3 years ago • 2 comments

If the pypi server is not reachable, pipreqs will hang forever

sify21 avatar Apr 22 '21 08:04 sify21

@sify21, I am noticing pipreqs throwing the following requests error upon not being able to reach the pypi-server:

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='pypi.python.org', port=443): Max retries exceeded with url: /pypi/anyio/json (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f55966d47c0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

I don't observe pipreqs hanging forever. Can you please provide more information around reproducing this issue.

kumiDa avatar May 07 '21 15:05 kumiDa

Sorry for the misunderstanding. It's not "unreachable", it's "reachable but at a slow speed", or "reachable but the packets are randomly lost". In my environment I can ping 'pypi.python.org', but when I curl https://pypi.python.org/pypi/anyio/json, it hangs sometimes. For example I curled twice, the first time it hangs; the second time it succeeds

me@ubuntu:~$ curl -vv https://pypi.python.org/pypi/anyio/json
*   Trying 151.101.108.223...
* Connected to pypi.python.org (151.101.108.223) port 443 (#0)
* found 148 certificates in /etc/ssl/certs/ca-certificates.crt
* found 594 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* Operation timed out after 0 milliseconds with 0 out of 0 bytes received
* Closing connection 0
curl: (28) Operation timed out after 0 milliseconds with 0 out of 0 bytes received
me@ubuntu:~$ curl -vv https://pypi.python.org/pypi/anyio/json
*   Trying 151.101.228.223...
* Connected to pypi.python.org (151.101.228.223) port 443 (#0)
* found 148 certificates in /etc/ssl/certs/ca-certificates.crt
* found 594 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / ECDHE_RSA_AES_128_GCM_SHA256
* 	 server certificate verification OK
* 	 server certificate status verification SKIPPED
* 	 common name: www.python.org (matched)
* 	 server certificate expiration date OK
* 	 server certificate activation date OK
* 	 certificate public key: RSA
* 	 certificate version: #3
* 	 subject: businessCategory=Private Organization,jurisdictionOfIncorporationCountryName=US,jurisdictionOfIncorporationStateOrProvinceName=Delaware,serialNumber=3359300,C=US,ST=Oregon,L=Beaverton,O=Python Software Foundation,CN=www.python.org
* 	 start date: Tue, 29 Sep 2020 00:00:00 GMT
* 	 expire date: Sun, 31 Oct 2021 00:00:00 GMT
* 	 issuer: C=US,O=DigiCert Inc,OU=www.digicert.com,CN=DigiCert SHA2 Extended Validation Server CA
* 	 compression: NULL
* ALPN, server accepted to use http/1.1
> GET /pypi/anyio/json HTTP/1.1
> Host: pypi.python.org
> User-Agent: curl/7.47.0
> Accept: */*
> 
< HTTP/1.1 301 Redirect to Primary Domain
< Connection: close
< Content-Length: 122
< Server: Varnish
< Retry-After: 0
< Location: https://pypi.org/pypi/anyio/json
< Content-Type: text/html; charset=UTF-8
< Accept-Ranges: bytes
< Date: Sat, 08 May 2021 02:51:03 GMT
< X-Served-By: cache-hnd18738-HND
< X-Cache: HIT
< X-Cache-Hits: 0
< X-Timer: S1620442263.033515,VS0,VE0
< Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
< X-Frame-Options: deny
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-Permitted-Cross-Domain-Policies: none
< 
* Closing connection 0
<html><head><title>301 Moved Permanently</title></head><body><center><h1>301 Moved Permanently</h1></center></body></html>

sify21 avatar May 08 '21 02:05 sify21