views:

55

answers:

0

I'm getting an error when trying to open a website url with Python 3.1, urllib & json

urllib.error.URLError:

Here's the code. The first website loads fine. The second one

import json
import urllib.request
import urllib.parse
import util

# This one works fine
response = urllib.request.urlopen('http://python.org/')
html = response.read()
print(html)

# parms - CSV filename, company, ....

p_filename = "c:\\temp\\test.csv"

jg_token = "zzzzzzzzzzzzzzzzzzzzzzzzz"
jg_proto = "https://"
jg_webst = "www.jigsaw.com/rest/"

jg_cmd_searchContact = "searchContact.json"

jg_key_companyName = "companyName"
jg_key_levels      = "levels"
jg_key_departments = "departments"

jg_args = {
        "token":jg_token,
        jg_key_companyName: "Technical Innovations",
        jg_key_departments: "HR"
        }

jg_url = jg_proto + jg_webst + jg_cmd_searchContact + "?" + urllib.parse.urlencode(jg_args)

    # This one generates teh error
result = json.load(urllib.request.urlopen(jg_url))

urllib.error.URLError:

File "c:\dev\xdev\PyJigsaw\searchContact.py", line 46, in result = json.load(urllib.request.urlopen(jg_url))

File "c:\dev\tdev\Python31\Lib\urllib\request.py", line 121, in urlopen return _opener.open(url, data, timeout)

File "c:\dev\tdev\Python31\Lib\urllib\request.py", line 349, in open response = self._open(req, data)

File "c:\dev\tdev\Python31\Lib\urllib\request.py", line 367, in _open '_open', req)

File "c:\dev\tdev\Python31\Lib\urllib\request.py", line 327, in _call_chain result = func(*args)

File "c:\dev\tdev\Python31\Lib\urllib\request.py", line 1098, in https_open return self.do_open(http.client.HTTPSConnection, req)

File "c:\dev\tdev\Python31\Lib\urllib\request.py", line 1075, in do_open raise URLError(err)