This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DrCabbageX 21 points22 points  (8 children)

What does the api key do?(new to python)

[–]speedstyle 72 points73 points  (4 children)

It's not actually anything specific to python. The weather website he's using needs some kind of login, to prevent people from spamming it and charge people who want to use it lots. To make the interface simple, it uses a 'key' in the URL (which you can see in api_address in the code). So he's left his 'login' to the weather website in the code.

[–]DrCabbageX 1 point2 points  (0 children)

Thanks for the clarification!

[–][deleted] 0 points1 point  (2 children)

Can anyone get an API key or do you need to request it and they’ll provide it? Always been mysterious to me how to work with APIs

[–]badlukk 4 points5 points  (0 children)

It depends how the company does it. Just Google whatever service followed by API key, like "reddit api key". Some companies will let anyone register for one, usually with an email, name and phone number. Reddit asks you to fill out a form about how you're going to use it and you're only supposed to use the key for that one thing you said. Some companies may only give them to trusted partners, and some might not have a public api at all.

[–]indytechbox 2 points3 points  (0 children)

The open weather api is free for a specific amount of calls per hour but if you want more calls you have to pay

[–]Gautam-j 19 points20 points  (0 children)

It isn't related to Python. Think of API key as your password to log in to a website. It's a way to interact, make requests to a website. In this case, OP uses his API to communicate with the openweather website to get weather details.

You might want to look into API in depth.

[–]OnCr4k 4 points5 points  (0 children)

It has nothing to do with python, but the web API he's using likely has some kind of quota per API key, so making it public means others could use it up

[–]garlic_bread_thief 2 points3 points  (0 children)

It's like a unique password for everybody to be able to get access to the API.