Reputation: 640
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.
Upvotes: 1
Views: 528
Reputation: 4783
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
Upvotes: 1
Reputation: 1212
It looks like your URL is suffering from the same problem that this question was seeing (accepted answer describes the problem; Here's the SSLLabs report on the host)
I was able to fix the SSL problem by downloading the cert from your original URL, exporting the two Entrust certificates to their own files (Entrust Certification Authority - L1K & Entrust.net), and then creating a .pem
trust chain out of them (the Entrust L1K cert is missing in the response):
cat entrustL1K.cer entrustNET.cer > entrust_chain.pem
Then, you can pass this trust chain to the requests.get
to fix the response:
url = "https://developer.uspto.gov/ibd-api/v1/patent/application?searchText=device&start=0&rows=2000"
requests.get(url, verify='entrust_chain.pem')
>>> <Response [200]>
Upvotes: 0