csparpa / pyowm

A Python wrapper around the OpenWeatherMap web API
https://pyowm.readthedocs.io
MIT License
791 stars 175 forks source link

urllib.error.HTTPError: HTTP Error 500: Internal Server Error for is_API_online() #133

Closed ghost closed 8 years ago

ghost commented 8 years ago

Thanks for this great library. However, a couple of things:

For the code

owm = pyowm.OWM('MY_VALID_KEY')
apionline = owm.is_API_online()
print(apionline)

I get

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/pyowm/commons/owmhttpclient.py", line 72, in call_API
    response = urlopen(url, None, timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 472, in open
    response = meth(req, response)
  File "/usr/lib/python3.5/urllib/request.py", line 582, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python3.5/urllib/request.py", line 510, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 590, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 500: Internal Server Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "owtest.py", line 42, in <module>
    apionline = owm.is_API_online()
  File "/usr/local/lib/python3.5/dist-packages/pyowm/webapi25/owm25.py", line 165, in is_API_online
    API_AVAILABILITY_TIMEOUT)
  File "/usr/local/lib/python3.5/dist-packages/pyowm/commons/owmhttpclient.py", line 74, in call_API
    raise api_call_error.APICallError(str(e), e)
pyowm.exceptions.api_call_error.APICallError: <exception str() failed>

However, the rest works in that I can retrieve a valid weather forecast, apart from this other issue I just logged https://github.com/csparpa/pyowm/issues/132

Thanks!

csparpa commented 8 years ago

Hello @lardconcepts thanks for reporting this!

It's a known issue - I'm going to release the lib in a few days and this is going to be fixed also

Thanks!

csparpa commented 8 years ago

Fixed with 5c64a0436b5082eb140d9b31800431219bdc5d42

Dnatalyaalex commented 4 years ago

Fixed with 5c64a04

Hello I face the issue too, but I have the newest version of the library. Can you please help to deal with it.

csparpa commented 4 years ago

@Dnatalyaalex I've just tested it, it's working. Probably the OWM API was unstable/crashed at the moment you've run your code Can you try again pls ?

Dnatalyaalex commented 4 years ago

@Dnatalyaalex I've just tested it, it's working. Probably the OWM API was unstable/crashed at the moment you've run your code Can you try again pls ?

Maybe you can help me... When I run script on my laptop it works, but when I use rundeck, it doesn't work. I noticed Rundeck uses Python 2.7 though I can run python 3.7 usin terminal. Could an error occur due to the wrong version of Python, and can I somehow indicate in the script which version it should use for this script? I have a lot of jobs on rundeck and I'm afraid that they will fall down after upgrading Pyton to 3.7 version. I installed urlib for python3.

Sorry for the primitive questions, I'm new to Python.

csparpa commented 4 years ago

Pls post here the full error trace (the one you see printend in your logs or on-screen), so I can understand what happens

Also pls specify the version of PyOWM that you're currently usign (eg with

pip show pyowm

Have you tried calling any other PyOWM function (eg. retrieve observed or forecast weather) ? Do you get errors? Or is it only with is_API_online function?

Dnatalyaalex commented 4 years ago

Pls post here the full error trace (the one you see printend in your logs or on-screen), so I can understand what happens

Also pls specify the version of PyOWM that you're currently usign (eg with

pip show pyowm

Have you tried calling any other PyOWM function (eg. retrieve observed or forecast weather) ? Do you get errors? Or is it only with is_API_online function?

Oh God I'm very sorry, I did not notice that this is a question on a specific function. I though just about urllib.error. Sorry that I spent your time

Anyway I post the trace, maybe somebody can help me

Traceback (most recent call last):

15:00:11 |   |   | File "/tmp/18444-76852-rundeck.dev-pro.net-dispatch-script.tmp.sh", line 26, in 15:00:11 |   |   | project = server.projects['ithelpdesk'] 15:00:11 |   |   | File "/usr/local/lib/python2.7/dist-packages/redmine/redmine_rest.py", line 426, in getitem 15:00:11 |   |   | return self.get(key) 15:00:11 |   |   | File "/usr/local/lib/python2.7/dist-packages/redmine/redmine_rest.py", line 498, in get 15:00:11 |   |   | json_data = self._redmine.get(target) 15:00:11 |   |   | File "/usr/local/lib/python2.7/dist-packages/redmine/redmine_rest.py", line 672, in get 15:00:11 |   |   | return self.open( page, parms ) 15:00:11 |   |   | File "/usr/local/lib/python2.7/dist-packages/redmine/redmine_rest.py", line 666, in open 15:00:11 |   |   | response = self.open_raw( page, parms, payload, HTTPrequest ) 15:00:11 |   |   | File "/usr/local/lib/python2.7/dist-packages/redmine/redmine_rest.py", line 636, in open_raw 15:00:11 |   |   | self._opener.open( fullUrl ) 15:00:11 |   |   | File "/usr/lib/python2.7/urllib2.py", line 435, in open 15:00:11 |   |   | response = meth(req, response) 15:00:11 |   |   | File "/usr/lib/python2.7/urllib2.py", line 548, in http_response 15:00:11 |   |   | 'http', request, response, code, msg, hdrs) 15:00:11 |   |   | File "/usr/lib/python2.7/urllib2.py", line 467, in error 15:00:11 |   |   | result = self._call_chain(args) 15:00:11 |   |   | File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain 15:00:11 |   |   | result = func(args) 15:00:11 |   |   | File "/usr/lib/python2.7/urllib2.py", line 916, in http_error_401 15:00:11 |   |   | url, req, headers) 15:00:11 |   |   | File "/usr/lib/python2.7/urllib2.py", line 894, in http_error_auth_reqed 15:00:11 |   |   | return self.retry_http_basic_auth(host, req, realm) 15:00:11 |   |   | File "/usr/lib/python2.7/urllib2.py", line 904, in retry_http_basic_auth 15:00:11 |   |   | return self.parent.open(req, timeout=req.timeout) 15:00:11 |   |   | File "/usr/lib/python2.7/urllib2.py", line 435, in open 15:00:11 |   |   | response = meth(req, response) 15:00:11 |   |   | File "/usr/lib/python2.7/urllib2.py", line 548, in http_response 15:00:11 |   |   | 'http', request, response, code, msg, hdrs) 15:00:11 |   |   | File "/usr/lib/python2.7/urllib2.py", line 473, in error 15:00:11 |   |   | return self._call_chain(args) 15:00:11 |   |   | File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain 15:00:11 |   |   | result = func(args) 15:00:11 |   |   | File "/usr/lib/python2.7/urllib2.py", line 556, in http_error_default 15:00:11 |   |   | raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)

15:00:11 |   |   | urllib2.HTTPError: HTTP Error 500: Internal Server Error

15:00:12 |   |   | Result: 1 15:00:12 |   |   | Failed: NonZeroResultCode: Result code was 1 15:00:12 |   |   | Execution failed: 76852 in project Redmine_Issue_Tracking: [Workflow result: , step failures: {1=Dispatch failed on 1 nodes: [rundeck.dev-pro.net: NonZeroResultCode: Result code was 1 + {dataContext=MultiDataContextImpl(map={ContextView(step:1, node:rundeck.dev-pro.net)=BaseDataContext{{exec={exitCode=0}}}, ContextView(node:rundeck.dev-pro.net)=BaseDataContext{{exec={exitCode=0}}}}, base=null)} ]},

Node failures: {rundeck.dev-pro.net=[NonZeroResultCode: Result code was 1 + {dataContext=MultiDataContextImpl(map={ContextView(step:1, node:rundeck.dev-pro.net)=BaseDataContext{{exec={exitCode=0}}}, ContextView(node:rundeck.dev-pro.net)=BaseDataContext{{exec={exitCode=0}}}}, base=null)} ]}, status: failed]

csparpa commented 4 years ago

Then sorry, but I don't understand what role PyOWM plays into this issue :-S

Your error log only tells me that you get a 500 error from the server, which is then not handled by urllib