xoolive / traffic

A toolbox for processing and analysing air traffic data
https://traffic-viz.github.io/
MIT License
361 stars 80 forks source link

Can't retrieve live state information from opensky #460

Closed simonrp84 closed 1 week ago

simonrp84 commented 3 weeks ago

Hello! If I try to use the api_states call to retrieve live information from the opensky data via traffic then I get this error message:

Retrying in 10 seconds... {retry} more time
Retrying in 10 seconds... {retry} more time
Retrying in 10 seconds... {retry} more time
Retrying in 10 seconds... {retry} more time
Retrying in 10 seconds... {retry} more time
Client error '401 ' for url 'https://opensky-network.org/api/states/all'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401
Retrying in 10 seconds... {retry} more time
Retrying in 10 seconds... {retry} more time
Retrying in 10 seconds... {retry} more time
Retrying in 10 seconds... {retry} more time
Retrying in 10 seconds... {retry} more time

And the states are not retrieved. My code is:

from traffic.data import opensky
sv = opensky.api_states()

This is not an issue with my machine being blocked by opensky as I can use curl https://opensky-network.org/api/states/all to successfully retrieve the states. I have added my login information to the traffic.conf file and have also tried without my credentials being in that file.

Any suggestions for what could be wrong?

If helpful, the debug info is:

DEBUG:httpcore.connection:close.started
DEBUG:httpcore.connection:close.complete
DEBUG:httpcore.connection:connect_tcp.started host='opensky-network.org' port=443 local_address=None timeout=5.0 socket_options=None
DEBUG:httpcore.connection:connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7fda81e29a30>
DEBUG:httpcore.connection:start_tls.started ssl_context=<ssl.SSLContext object at 0x7fda81e0c150> server_hostname='opensky-network.org' timeout=5.0
DEBUG:httpcore.connection:start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7fda81e29370>
DEBUG:httpcore.http11:send_request_headers.started request=<Request [b'GET']>
DEBUG:httpcore.http11:send_request_headers.complete
DEBUG:httpcore.http11:send_request_body.started request=<Request [b'GET']>
DEBUG:httpcore.http11:send_request_body.complete
DEBUG:httpcore.http11:receive_response_headers.started request=<Request [b'GET']>
DEBUG:httpcore.http11:receive_response_headers.complete return_value=(b'HTTP/1.1', 403, b'', [(b'Server', b'nginx/1.17.6'), (b'Date', b'Mon, 19 Aug 2024 09:01:34 GMT'), (b'Transfer-Encoding', b'chunked'), (b'Connection', b'keep-alive'), (b'X-Content-Type-Options', b'nosniff'), (b'X-XSS-Protection', b'1; mode=block'), (b'Cache-Control', b'no-cache, no-store, max-age=0, must-revalidate'), (b'Pragma', b'no-cache'), (b'Expires', b'0'), (b'X-Frame-Options', b'DENY')])
INFO:httpx:HTTP Request: GET https://opensky-network.org/api/states/all "HTTP/1.1 403 "
DEBUG:httpcore.http11:receive_response_body.started request=<Request [b'GET']>
DEBUG:httpcore.http11:receive_response_body.complete
DEBUG:httpcore.http11:response_closed.started
DEBUG:httpcore.http11:response_closed.complete

Please follow these steps to make it more efficient to solve your issue:

You may activate the DEBUG level with the following snippet:

import logging
logging.basicConfig(level=logging.DEBUG)
simonrp84 commented 3 weeks ago

For what it's worth, I am aware of: #413, which is also mine, but this appears to be a different issue. In that case I couldn't retrieve the states via curl and so it was an opensky issue. Here I can successfully retrieve the states outside of traffic so it's a library problem I think. Hence opening a new issue - apologies if you would have preferred I re-opn the old issue!

xoolive commented 3 weeks ago

Hi Simon, that is weird as I cannot reproduce on my side. Are you using the latest version of pyopensky? If yes, can you check with the HEAD of the repository?

xoolive commented 1 week ago

Hi @simonrp84 I published this morning a new version of pyopensky (wrapped by traffic) to better handle this kind of errors, can you try again? If it fails, please reopen another issue in pyopensky.

simonrp84 commented 1 week ago

Sorry for not getting back to you on this - busy few weeks! Will try with pyopensky as requested in the next days.