Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8550661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:00:10+00:00 2026-06-11T14:00:10+00:00

Attempting to parse json from a url requiring login. Including all my code here

  • 0

Attempting to parse json from a url requiring login. Including all my code here as I’m not sure where the error is.

try: import simplejson as json
except ImportError: import json
import urllib2

username = 'user'
password = '1234'
url = "https://www.blah.com/someplace"

# set up the username/password/url request
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, "https://www.blah.com", username, password)
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)
request = urllib2.Request(url)
response = opener.open(request)

# option 1
json_object = json.loads(str(response))

#option 2
json_object = json.loads(response)

If I run the code with option 1 (commenting out option 2), I get this error:

Traceback (most recent call last):
  File "jsontest.py", line 22, in <module>
    json_object = json.loads(str(request))
  File "/usr/lib/python2.7/dist-packages/simplejson/__init__.py", line 413, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 402, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 420, in raw_decode
    raise JSONDecodeError("No JSON object could be decoded", s, idx)
simplejson.decoder.JSONDecodeError: No JSON object could be decoded: line 1 column 0 (char 0)

If I run option 2:

Traceback (most recent call last):
  File "jsontest.py", line 23, in <module>
    json_object = json.loads(request)
  File "/usr/lib/python2.7/dist-packages/simplejson/__init__.py", line 413, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 402, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer

My sample JSON is valid as far as I can tell:

{“set1”:[{“data1″:”411″,”data2″:”2033″,”data3″:”1″,”data4″:”43968077″,”data5″:”217″,”data6″:”106828″,”data7”:[]}],
“set2”:{“data8″:”411″,”data9″:”2033″,”data10″:”43968077″,”data11″:”217223360″,”data12″:”106828”}}

simplejson version = 2.3.2,
Python 2.7.3

Very new to all this so any pointers would be very helpful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:00:12+00:00Added an answer on June 11, 2026 at 2:00 pm

    You want to decode the response, not the request:

    json_object = json.load(response)
    

    The response is a file-like object, so you can use .load() to have the json library read it directly.

    Alternatively (at the cost of some temporary memory use), use the .loads() function with the fully read response:

    json_object = json.loads(response.read())
    

    Note that python 2.7 already includes the simplejson library, renamed to json:

    import json
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to parse some JSON from a URL via Flash/AS3. Here's my
I am attempting to parse the incoming JSON from XBMC (Eden Beta v3), an
I am attempting to parse an XML and store the URL from one element
I am attempting to parse a JSON feed from Yahoo Pipes to turn it
I am attempting to parse some json I am getting back from a service.
I am attempting to parse, not evaluate, rails ERB files in a Hpricot/Nokogiri type
I'm attempting to parse a JSON feed using the LastFM API but there are
So I've managed to get the feed from twitter and am attempting to parse
I am attempting to parse keydown events from the numberpad with the following: $('#myDiv').keydown(function(e)
I am attempting to parse the following JSON response with GSON: { total: 15,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.