parkerhancock / patent_client

A collection of ORM-style clients to public patent data
Other
92 stars 36 forks source link

httpx.HTTPStatusError: Client error '403 #171

Open amit-trexo opened 5 months ago

amit-trexo commented 5 months ago

I am getting the below exceptions regularly after fetching 115-120 applications in my django rest framework. Initial investigation pointed to peds rate limiter, but on restart I am able to fetch another 120 set. So something is wrong in USApplication.objects.get(application_number).

Below is the error stack trace:

httpx.HTTPStatusError: Client error '403 Forbidden' for url 'https://ped.uspto.gov/api/queries' For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403 exiInternal Server Error: /api/patent-cli/17700494/ Traceback (most recent call last): File "/home/ubuntu/python/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) File "/home/ubuntu/python/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, callback_kwargs) File "/home/ubuntu/python/venv/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 56, in wrapper_view return view_func(*args, *kwargs) File "/home/ubuntu/python/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 104, in view return self.dispatch(request, args, kwargs) File "/home/ubuntu/python/venv/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch response = self.handle_exception(exc) File "/home/ubuntu/python/venv/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception self.raise_uncaught_exception(exc) File "/home/ubuntu/python/venv/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception raise exc File "/home/ubuntu/python/venv/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch response = handler(request, *args, *kwargs) File "/home/ubuntu/python/venv/lib/python3.10/site-packages/rest_framework/decorators.py", line 50, in handler return func(args, kwargs) File "/home/ubuntu/python/drf/api/views.py", line 21, in getData app = USApplication.objects.get(application_number) File "/home/ubuntu/python/venv/lib/python3.10/site-packages/patent_client/util/manager.py", line 180, in get length = len(mger) File "/home/ubuntu/python/venv/lib/python3.10/site-packages/patent_client/util/manager.py", line 165, in len return self.count() File "/home/ubuntu/python/venv/lib/python3.10/site-packages/patent_client/_sync/uspto/peds/manager.py", line 59, in count max_length = (api.create_query(self.get_query_params())).num_found File "/home/ubuntu/python/venv/lib/python3.10/site-packages/patent_client/_sync/uspto/peds/api.py", line 118, in create_query self.check_response(response) File "/home/ubuntu/python/venv/lib/python3.10/site-packages/patent_client/_sync/uspto/peds/api.py", line 58, in check_response raise e if alive else PedsDownException(reason) File "/home/ubuntu/python/venv/lib/python3.10/site-packages/patent_client/_sync/uspto/peds/api.py", line 55, in check_response response.raise_for_status() File "/home/ubuntu/python/venv/lib/python3.10/site-packages/httpx/_models.py", line 761, in raise_for_status raise HTTPStatusError(message, request=request, response=self)

jacob-hart commented 3 months ago

I have the same issue when attempting to use USApplication.get too often. The USPTO API seems to lock up after some number of uses and then returns 403 for a while after.

I visited https://ped.uspto.gov/api/queries after getting locked up and it had this result in Firefox:

403 ERROR
The request could not be satisfied.
Request blocked. We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.

Generated by cloudfront (CloudFront)
Request ID: -V8sIZ3bGsL6jllfzvSrO6QoZnUAkejFFWv_DyPQVQeweI-PrNsu6Q==

Maybe patent_client users are seen as spam traffic?