×

Notice

The forum is in read only mode.

Beginner issue - error while authentication

3 years 7 months ago - 3 years 7 months ago #1450 by kerberos
Good Morning,

i am starting some things using the API
For this i have imported the Python library as instructed and i've used your example to get the aircraft from my sensors.
from opensky_api import OpenSkyApi

api = OpenSkyApi(USERNAME, PASSWORD)
states = api.get_my_states()
print(states)
for s in states.states:
    print(s.sensors)

However when i run the script, it tells me:
NameError: name 'USERNAME' is not defined

I've replaced of course "USERNAME" with my real username.
Any idea where i need to start troubleshooting? username and password are accepted using the REST API
3 years 7 months ago #1451 by kerberos
Hm, looks like i have found the error by myself.

If i put the username and the password in quotes like "username", "password" i do not get the error but data.

Maybe it would be an idea to change the example :)
3 years 7 months ago #1453 by jluebbe
upper case variables are usually constants you have defined somewhere in the code before like:
USERNAME = "my_username"
PASSWORD = "my_password"

Then it becomes easier to share code snippets without your personal data.
3 years 7 months ago #1455 by kerberos
I know, but the example in the documentation is wrong.
Powered by Kunena Forum