Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication error with USPTO after long time between requests #174

Open
david-lightbringer opened this issue Aug 2, 2024 · 1 comment

Comments

@david-lightbringer
Copy link

Example code that crashes:

import patent_client
import time
doc1 = patent_client.PublicSearchDocument.objects.get('6103599')
time.sleep(2000)
doc2 = patent_client.PublicSearchDocument.objects.get('9421317')

The result is
Client error '401 Unauthorized' for url 'https://ppubs.uspto.gov/dirsearch-public/searches/counts'

The reason is pretty simple - the PublicSearchAPI or (or rather public_search_api in patent_client/_async/uspto/public_search/manager.py) needs a new session because the old authentication token has a timeout of 1800 seconds. The timeout seems to reset after each use, so continuous use of the same session works as long as no two request are separated by more than 1800 seconds.

As a workaround for others with the same issue until this is updated you can do something like:

import patent_client
import time
doc1 = patent_client.PublicSearchDocument.objects.get('6103599')
time.sleep(2000)
from patent_client._sync.uspto.public_search.manager import public_search_api
public_search_api.get_session()
doc2 = patent_client.PublicSearchDocument.objects.get('9421317')

Where the session is force-updated before the second search.

@kcoombs
Copy link

kcoombs commented Aug 14, 2024

I've also been running into this issue in my project.

For now I detect when I get a 401 response, force a new session from public_search_api as described above, and retry.

Thanks, @david-lightbringer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants