Hello,

I'm working on a small project to acquire information from regulations.gov using their API. It's fairly simple (codewise) what I'm trying to do. However, I get stuck with a "HTTP error 403: Forbidden". It means I'm connecting, but something seems to be the matter.
I've been in contact with the people working on the API. They said that my API and Accept header call are fine. I don't know what the problem is. Here is the code:

import urllib2
from json import load

url = 'http://api.data.gov:80/regulations/v3/documents.json?api_key=API_KEY'
request = Request(url, headers={"Accept":"application/json;charset=UTF-8"})
response = urlopen(request)
json_obj = load(response)

In essence, the problem is at the urlopen() request. Any pointers would be a great help. Also, you can go here to acquire an API key: https://api.data.gov/signup/

Recommended Answers

All 5 Replies

Yup. As you know, it's not good practice to share your api key, for obvious reasons. Hence, my omitting it from the discussion.

You are also not defining the Request class.

That's actually something I forgot to add while typing my code. I have it as:

from urllib2 import urlopen
from urllib2 import Request

My apologies for not having that in there.
Like I said in my explanation, the problem isn't getting to the database, it's extracting the information. I've verified this with the guys that work the API. The reason why I'm asking on Daniweb is because those gents have never worked with Python. I figured if someone here messed about with the API, they'd understand the problem and help me out.
I'm working with the NPR API, and everything seems fine there, but this one seems not to work.
Thank you for taking the time to check my post, btw.

Can you paste some results you get after running your code here.
I think you are talking about how to format the data for use.

I stand to be corrected anyway.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.