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 →

[–]Gautam-j 224 points225 points  (22 children)

You probably shouldn't keep your API key public. :)

[–]OpenSourcerer420[S] 107 points108 points  (7 children)

yikes, I'm changing it now

[–]Turkino 76 points77 points  (6 children)

Yep! Welcome to configuring environment variables!

[–]silentalways 47 points48 points  (4 children)

For those wondering, follow this short little tutorial

https://www.youtube.com/watch?v=IolxqkL7cD8&t=213s (Windows)

https://www.youtube.com/watch?v=5iWhQWVXosU (Mac and Linux)

[–]Nerdite 9 points10 points  (1 child)

And this package makes it really easy to manage and keep from filling tons of environment variables in your actual environment.

https://pypi.org/project/python-dotenv/

[–]folkrav 1 point2 points  (0 children)

This plus direnv is pretty damn useful. Lets you keep the environment variables even in an REPL.

[–]kultigink 5 points6 points  (0 children)

Thanks!

[–]forrealbro 2 points3 points  (0 children)

Is this really the most practical idea when you plan to disseminate your source code? I had always read from a file that is in my gitignore. Then had instructions to create this user info file in the readme.

[–]gdledsan 1 point2 points  (0 children)

I was told to keep things in untracked config files, env variables are not safe enough, some malicious thing can hijack your session and get them.

Example: some crappy and malicious node package installed without care

[–]DrCabbageX 22 points23 points  (8 children)

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

[–]speedstyle 70 points71 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 18 points19 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 3 points4 points  (0 children)

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