Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1793

ConnectionResetError with Python requests and urllib libraries when accessing specific URL

$
0
0

I'm encountering a ConnectionResetError when attempting to access a specific URL using both Python requests and urllib libraries. Despite providing appropriate headers, the connection is being forcibly closed by the remote host. This issue occurs consistently, and I'm seeking insights into its cause and potential solutions.

Here's the code snippet I'm using:

import requestsheaders = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7','Accept-Language': 'en-US,en;q=0.9','Cache-Control': 'no-cache','Connection': 'keep-alive','DNT': '1','Pragma': 'no-cache','Sec-Fetch-Dest': 'document','Sec-Fetch-Mode': 'navigate','Sec-Fetch-Site': 'none','Sec-Fetch-User': '?1','Upgrade-Insecure-Requests': '1','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36','sec-ch-ua': '"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"','sec-ch-ua-mobile': '?0','sec-ch-ua-platform': '"Windows"',}response = requests.get('https://newjersey.mylicense.com/verification/Search.aspx', headers=headers)

And here's the error I'm receiving:

('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))

Libraries being used:

  • requests==2.31.0
  • urllib3==2.2.1

I've attempted to access the URL using both the requests and urllib libraries, providing the necessary headers to mimic a browser request. I expected the connection to be established successfully, allowing me to retrieve the desired content. However, I consistently received a ConnectionResetError indicating that the connection was forcibly closed by the remote host.

The URL in question functions as expected when accessed through a web browser, indicating that the issue may lie within the Python libraries rather than with the server itself.


Viewing all articles
Browse latest Browse all 1793

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>