URLLib.Request Errors

3050
10
08-05-2022 09:34 AM
jaykapalczynski
Frequent Contributor

Hello... I am trying to grab some JSON text that is on a webpage via a WordPress Api output.  There is nothing on this page except the JSON string.

If I go to CMD prompt and navigate to my Python folder I can confirm I have python and PIP

 

C:\Python310>py --version
Python 3.10.6

C:\Python310>py -m pip --version
pip 22.2.1 from C:\Python310\lib\site-packages\pip (python 3.10)

 

 

import arcpy
import requests
import json
import uuid
from urllib.request import urlopen
import urllib
import requests

url = "https://somewebsite/"

response = urlopen(url)
data_json = json.loads(response.read)
print (data_json)

 

I am trying to above code but keep getting this error:

Traceback (most recent call last):
File "C:\Users\t\Desktop\JSONSamples\readJson.py", line 7, in <module>
from urllib.request import urlopen
ImportError: No module named request

Any thoughts?  Do I need to install something additional to Python?  Any help would be much appreciated.

 

 

0 Kudos
10 Replies
StuartMoore
Occasional Contributor III

this might help:

 

        fsURL = "http://yourwebsite.com"
        payload3 = {'updates': updateAttr, 'f': 'json','token' : aToken}
        r3 = requests.get(fsURL, params=payload3, proxies=proxies)
        print(r3.text)

 

 

just ignore the payload if you dont need to pass any parameters, same goes for the proxy

forgot to say the above just uses requests

Stu 

0 Kudos