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

Bad API key causes UnboundLocalError #2005

Open
bobpaul opened this issue Jan 23, 2025 · 0 comments
Open

Bad API key causes UnboundLocalError #2005

bobpaul opened this issue Jan 23, 2025 · 0 comments

Comments

@bobpaul
Copy link

bobpaul commented Jan 23, 2025

Basically the same situation as #1827 except that I had an API key filled in, but then generated a new API key in PyMedusa, and then I saw this error in SabNZB:

Traceback (most recent call last):
File "/usr/share/nzbget/ppscripts/nzbToSickBeard.py", line 278, in <module>
result = nzbToMedia.main(sys.argv, section)
File "/usr/share/nzbget/ppscripts/nzbToMedia.py", line 763, in main
result = sab.process_script()
File "/usr/share/nzbget/ppscripts/core/processor/sab.py", line 13, in process_script
return nzb.process(
~~~~~~~~~~~^
input_directory=os.environ['SAB_COMPLETE_DIR'],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<5 lines>...
failure_link=os.environ['SAB_FAILURE_URL'],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/usr/share/nzbget/ppscripts/core/processor/nzb.py", line 127, in process
result = tv.process(section_name, input_directory, input_name, status, client_agent, download_id, input_category, failure_link)
File "/usr/share/nzbget/ppscripts/core/auto_process/tv.py", line 337, in process
return init_sickbeard.fork_obj.api_call()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/usr/share/nzbget/ppscripts/core/auto_process/managers/pymedusa.py", line 122, in api_call
if not jdata.get('status') or not jdata['status'] == 'success':
^^^^^
UnboundLocalError: cannot access local variable 'jdata' where it is not associated with a value

I think it would be good to add error handling to the request itself. If a bad auth token (or bad api key) is used, the PyMedusa v2 api returns HTTP 401 along with a response body of {"error": "No authorization token."}. I think a reasonable way to do error handling generically would be to catch any non-HTTP 200 responses and who the HTTP response code number along with the response body. That way the Sickbeard fork is responsible for presenting a reasonable error message and users aren't shown an uncaught exception that isn't descriptive of the problem.

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

1 participant