Skip to content
Advertisement

Ubuntu 18.04 python 2.7 urllib request not getting data

I have this python script which works with no problem on ubuntu 16.04 But it wont get data in ubuntu 18.04, any idea what the problem could be? No errors.

JavaScript

Output:

JavaScript

Full code is here : https://github.com/papampi/nvOC_by_fullzero_Community_Release/blob/Dual-cuda/WTM_SWITCHER

Advertisement

Answer

Since you’re using the Requests library, you should use it on each API. Requests provides a method to extract JSON, so you don’t need to call the json module yourself.

When multiple things can go wrong, it’s not a good idea to bundle them all together in one line. Do them in stages so you can see exactly where the error occurred, and deal it with it appropriately. Also, using unnamed except blocks is rarely a good idea: you might catch something that you don’t know how to handle.

Here’s a re-organized version of your code.

JavaScript

typical output

JavaScript

Update: I’ve improved the error-handling of this code.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement