-1

When I try to run this sequence of commands (using python):

url = "http://www.bom.gov.au/fwo/IDV60701/IDV60701.9536.json"
response = urllib.urlopen(url)
print response.read()

I get the following output:

<HTML><HEAD>
<TITLE>Access Denied</TITLE>
</HEAD><BODY>
<H1>Access Denied</H1> 
You don't have permission to access  
"http&#58;&#47;&#47;www&#46;bom&#46;gov&#46;au&# 
 47;fwo&#47;IDV60701&#47;IDV60701&#46;95936&#46;json" on this server. 
<P>
Reference&#32;&#35;18&#46;d4c2ce17&#46;1533360576&#46;56049f8
</BODY>
</HTML>

But when I access this url http://www.bom.gov.au/fwo/IDV60701/IDV60701.95936.json from a browser the json file displays correctly. How can I read this json file from my python script?

Spinor8
  • 1,587
  • 4
  • 21
  • 48
  • Add headers as `User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36` in your request and you get your response – utks009 Aug 04 '18 at 09:54
  • How can I add a header to my urllib request? This does not seem possible. – Marcus Scipio Aug 04 '18 at 10:32
  • you can reffer this for [link](https://stackoverflow.com/questions/7933417/how-do-i-set-headers-using-pythons-urllib) – utks009 Aug 04 '18 at 11:47

1 Answers1

0

I dont know whats the problem there, but I get this with requests package.

install requests package with pip : pip install requests

then do this:

resp = requests.get('http://www.bom.gov.au/fwo/IDV60701/IDV60701.95936.json')
print resp.json
Mehrdad Pedramfar
  • 10,941
  • 4
  • 38
  • 59