nomnoms12 / saucenao_api

Wrapper for SauceNAO JSON API
https://pypi.org/project/saucenao-api
GNU General Public License v3.0
64 stars 14 forks source link

Invalid API key #9

Closed khoadng closed 3 years ago

khoadng commented 3 years ago

Got this error when running this code snippet

Error

Exception has occurred: BadKeyError
Invalid API key
  File "C:\Users\Admin\Projects\test.py", line 4, in <module>
    results = sauce.from_url('https://i.imgur.com/oZjCxGo.jpg')  # or from_file()

Code

from saucenao_api import SauceNao

sauce = SauceNao()
results = sauce.from_url('https://i.imgur.com/oZjCxGo.jpg')  # or from_file()

best = results[0]  # results sorted by similarity
print(best.author)

Do I need to provide an API key or something?

nomnoms12 commented 3 years ago

The error occurred because the server returned an HTTP 403 Forbidden response:

{'header': {'status': -1, 'message': 'The anonymous account type does not permit API usage.'}}

SauceNao probably no longer supports anonymous requests, and yes, you will have to register and pass an API key with every request. (With the key, the request is successful.)

nomnoms12 commented 3 years ago

@khoadng You have to pass the API key to the SauceNao class:

# Replace the key with your own
sauce = SauceNao('077f16b38a2452401790540f41246c7d951330c0')

To get the key, register using the link: https://saucenao.com/user.php?page=search-api

nomnoms12 commented 3 years ago

I think this can't be considered a bug in the library. If SauceNao's policy doesn't change in the next few days, I'll make api_key a required parameter and update the examples.

khoadng commented 3 years ago

Other than this, everything works flawlessly. Nice work! Thanks for this awesome library.