Search code examples
pythonpython-3.xpython-requestsurllib

I am trying to retrieve a URL but keep running into an SSLError: HTTPSConnectionPool(host='developer.uspto.gov', port=443)


I am trying to retrieve a URL from an API set up by the USPTO. Their system provides a URL for the query, and it works just fine when searched in a web browser. But I keep receiving this error when doing so in Python3

I have tried using both urllib and requests to retrieve the data.

My code:

import requests

link = new_url
f = requests.get("https://developer.uspto.gov/ibd-api/v1/patent/application?searchText=device&start=0&rows=2000")
print(f.text)

Error:

SSLError: HTTPSConnectionPool(host='developer.uspto.gov', port=443): Max 
retries exceeded with url: /ibd-api/v1/patent/application? 
searchText=device&start=0&rows=2000 (Caused by SSLError(SSLError("bad 
handshake: Error([('SSL routines', 'tls_process_server_certificate', 
'certificate verify failed')])")))

I would like to be able to read the content of this URL using the json library.


Solution

  • This error can easily be solved using by adding verify = False to your get request.

    I would recommend replacing your current code with this one:

    import requests
    
    link = new_url
    f = requests.get("https://developer.uspto.gov/ibd-api/v1/patent/application?searchText=device&start=0&rows=2000", verify=False)
    print(f.text)
    

    Here is a bit more info SSL Cert Verification.

    hope this helps