0

I am trying to access an API and it is mentioned that it gives in HTML. I went through these answers

(Get html using Python requests?) but I am not getting my results. I just wanted to make sure I am doing it correctly as I am getting error like this ("'{"request":{"category_id":"717234","command":"category"},"data":{"error":"invalid or missing api_key'" Is this API not working ? Is there any way to get HTML data and convert them to CSV or excel? Here is the code which I am using.

import requests
URL = "https://api.eia.gov/category?api_key=YOUR_API_KEY_HERE&category_id=717234"
r = requests.get(url = URL)
r.text[:100]
2
  • you can use this link to get a key eia.gov/opendata/register.php Commented Jun 30, 2019 at 21:48
  • That makes sense I only had to register with that and it would send API key. Thanks Ghasseen. Commented Jun 30, 2019 at 21:55

2 Answers 2

1

you are using a invalid api the link to your html page is not working :

import requests
URL = "https://api.eia.gov/category?api_key=YOUR_API_KEY_HERE&category_id=717234"
headers = {'Accept-Encoding': 'identity'}
r = requests.get(URL, headers=headers)
print(r.text[:100])

output:

{"request":{"category_id":"717234","command":"category"},"data":{"error":"invalid or missing api_key

i try to change the link of the link with that one given in the answer that you put the link and i get a result :

import requests
URL = "http://www.wrcc.dri.edu/WRCCWrappers.py?sodxtrmts+028815+por+por+pcpn+none+mave+5+01+F"
headers = {'Accept-Encoding': 'identity'}
r = requests.get(URL, headers=headers)
print(r.text[:100])

output:

<!DOCTYPE html>
<HTML>
<HEAD><TITLE>Average of Precipitation, Station id: 028815</TITLE></HEAD>
<BO

as a solution you can use an external api the devoloper mode of that api : https://www.eia.gov//developer// or check this link to get a key :https://www.eia.gov/opendata/

Sign up to request clarification or add additional context in comments.

Comments

0

Its not an error.
seems to me like youre missing your API KEY.

this is what wrote in the link you put:

{"request":{"category_id":"717234","command":"category"},"data":{"error":"invalid or missing api_key. For key registration, documentation, and examples see https:\/\/www.eia.gov\/developer\/"}}

2 Comments

Yes thats correct it is mentioned in the website that this Key can be accessed, so I was just thinking if there is any other way or correct code to access it.
Which api are you trying to access?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.