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

ValueError: ODP API key is not set #177

Open
ishu121992 opened this issue Sep 10, 2024 · 2 comments
Open

ValueError: ODP API key is not set #177

ishu121992 opened this issue Sep 10, 2024 · 2 comments

Comments

@ishu121992
Copy link

ishu121992 commented Sep 10, 2024

Below is my simple code:
from patent_client.odp import USApplicationBiblio
from dotenv import load_dotenv
import os

load_dotenv() # Load variables from .env file

api_key = os.getenv('PATENT_CLIENT_ODP_API_KEY') # Fetch the API key

if not api_key:
raise ValueError("ODP API key is not set")

app = USApplicationBiblio.objects.get("16123456") # Retrieve application

I HAVE TRIED SLIGHT VARIATIONS AS WELL (like ODP_API_KEY), but it doesn't work.

Getting Error:

ValueError Traceback (most recent call last)
Cell In[5], line 1
----> 1 app = USApplicationBiblio.objects.get("16123456") # Retrieve application

File ~/.local/lib/python3.10/site-packages/patent_client/util/pydantic_util.py:47, in ClassProperty.get(self, instance, owner)
46 def get(self, instance, owner):
---> 47 return self.getter(owner)

File ~/.local/lib/python3.10/site-packages/patent_client/util/pydantic_util.py:91, in BaseModel.objects(cls)
89 manager_module = cls.module.split(".model")[0] + ".manager"
90 manager_path = manager_module + "." + cls.name + "Manager"
---> 91 return get_class(manager_path, base_class=cls)()

File ~/.local/lib/python3.10/site-packages/patent_client/util/pydantic_util.py:72, in get_class(class_name, base_class)
70 module_name, class_name = absolute_model_name.rsplit(".", 1)
71 try:
---> 72 module = importlib.import_module(module_name)
73 return getattr(module, class_name)
74 except (ImportError, AttributeError) as e:

File /usr/lib/python3.10/importlib/init.py:126, in import_module(name, package)
124 break
125 level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)

File :1050, in _gcd_import(name, package, level)

File :1027, in find_and_load(name, import)

File :1006, in find_and_load_unlocked(name, import)

File :688, in _load_unlocked(spec)

File :883, in exec_module(self, module)

File :241, in _call_with_frames_removed(f, *args, **kwds)

File ~/.local/lib/python3.10/site-packages/patent_client/_sync/uspto/odp/manager.py:29
16 if tp.TYPE_CHECKING:
17 from .model import (
18 Assignment,
19 Continuity,
(...)
27 USApplicationBiblio,
28 )
---> 29 api = ODPApi()
32 class USApplicationManager(Manager):
33 default_filter = "appl_id"

File ~/.local/lib/python3.10/site-packages/patent_client/_sync/uspto/odp/api.py:38, in ODPApi.init(self)
36 def init(self):
37 if SETTINGS.odp_api_key is None:
---> 38 raise ValueError("ODP API key is not set")
39 self.client = PatentClientSession(headers={"X-API-KEY": SETTINGS.odp_api_key})

ValueError: ODP API key is not set

@david-lightbringer
Copy link

You'll need to load your dot-env before any import of patent client. So move the load before the patent-client import and try it!

@Hobly
Copy link

Hobly commented Sep 10, 2024

Just to double check the obvious: you do have a .env file that contains your api key right? :)

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

3 participants