Skip to content

Authentication error with USPTO after long time between requests #174

@david-lightbringer

Description

@david-lightbringer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions