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

Problem with EPO credentials #170

Open
deg opened this issue Jun 9, 2024 · 3 comments
Open

Problem with EPO credentials #170

deg opened this issue Jun 9, 2024 · 3 comments

Comments

@deg
Copy link

deg commented Jun 9, 2024

I've moved past my earlier false alarm in #160 but now have a similar problem with the EPO API.

patent_client._sync.epo.ops.session.OpsAuthenticationError: Failed to authenticate with EPO OPS! Please check your credentials. See the setup instructions at https://patent-client.readthedocs.io/en/stable/getting_started.html

I do have the credentials set correctly, I think:

>>> os.environ["PATENT_CLIENT_EPO_API_KEY"]
'2pwQ_ELIDED_VBTl4'
>>> os.environ["PATENT_CLIENT_EPO_SECRET"]
'pJA__ELIDED__WHH'

I've also successfully called the EPO API directly with code like

    auth_url = "https://ops.epo.org/3.2/auth/accesstoken"
    response = requests.post(
        auth_url,
        auth=HTTPBasicAuth(client_id, client_secret),
        data={"grant_type": "client_credentials"},
    )

    if response.status_code == 200:
        token = response.json().get("access_token")
        return token
...
    base_url = (
        "https://ops.epo.org/3.2/rest-services/published-data/publication/epodoc/"
    )
    headers = {"Authorization": f"Bearer {access_token}", "Accept": "application/json"}
    response = requests.get(base_url + publication_number, headers=headers)

I assume this is my operator error again, but I don't see where.

Do I have the correct keys? developers.epo.org tells me that I have a "consumer key" and consumer secret key". Are these the same thing as the EPO OPS API keys that your API needs? Or do I need to get a different set?

@wschlecht
Copy link

Hi David,

I am having a similar issue, which is odd because I was able to successfully use my EPO OPS API keys with patent-client just a week or so ago, but today I am getting an "Inpadoc: Failed to authenticate with EPO OPS!" error.

One thing which appears incorrect in your code is that "PATENT_CLIENT_EPO_SECRET" should be "PATENT_CLIENT_EPO_API_SECRET"

I was (at least previously) able to successfully use my EPO OPS keys with patent-client using the below code:
os.environ['PATENT_CLIENT_EPO_API_KEY'] = #####
os.environ['PATENT_CLIENT_EPO_API_SECRET'] = #####

So perhaps try changing the names of your environment variables and see if that works for you, but as I said I'm encountering a similar issue, despite being able to authenticate my EPO OPS keys on https://developers.epo.org/ (with their test API), so it's possible there is something else going on.

@wschlecht
Copy link

wschlecht commented Jun 13, 2024

I was actually able to identify that the source of my particular error was coming from patent_client/_sync/epo/ops/session.py and in particular the build_refresh_request method of the OpsAuth class. I was able to fix my issue by reformatting the header of the request as follows:

def build_refresh_request(self):
token = base64.b64encode(f"{self.key}:{self.secret}".encode()).decode('utf-8')
headers = {"Authorization": f"Basic {token}"}
return httpx.Request(
"POST",
self.auth_url,
headers=headers,
data={"grant_type": "client_credentials"}
)

This is not my area of expertise, but unless I am missing something I don't believe the current patent-client library will be able to successfully authenticate EPO OPS credentials until this method is patched to have the correct header format.

@barisortac
Copy link

barisortac commented Jul 30, 2024

Also docs are wrong here:
https://patent-client.readthedocs.io/en/latest/getting_started.html

As mentioned by @wschlecht, it should be PATENT_CLIENT_EPO_API_SECRET, but not PATENT_CLIENT_EPO_SECRET, I spent half an hour to figure it out 🤦.

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