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 8190685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:43:54+00:00 2026-06-07T03:43:54+00:00

def test(request): u=username p= ‘password’ url=’url’ req = urllib2.Request(url) base64string = base64.encodestring(‘%s:%s’ % (u

  • 0
def test(request):
    u="username"
    p= 'password'
    url='url'
    req = urllib2.Request(url)
    base64string = base64.encodestring('%s:%s' % (u , p )).replace('\n', '')
    d = {}
    req.add_data(d)  //while authentication i dont send any data, but it is treated as POST request only if data is sent, so sending empty data
    req.add_header("Authorization", "Basic %s" % base64string) 
    req.add_header('Accept', 'application/json')  
    result = urllib2.urlopen(req)

    print result
    return HttpResponse(result) 

In browser, the response is coming as (bcoz of HttpResponse)

{"token":"abcdef"}  //means correct

but the command “print result” is giving something like this :

<addinfourl at 140585554707088 whose fp = <socket._fileobject object at 0x7fdca009e5d0>>

So, i am unable to do any operations on that variable . What i want is only the “token” value from the string . I tried :

type(result) // error
json.dumps(result)  //error 
json.loads(result)  //error 
token = result.token     //error
  • 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-07T03:43:55+00:00Added an answer on June 7, 2026 at 3:43 am

    you should instead use

    result.read()
    

    result is the result object.

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

Sidebar

Related Questions

I have this test case def setUp(self): self.user = User.objects.create(username=tauri, password='gaul') def test_loginin_student_control_panel(self): c
So I have this URL scheme: (r'^test/(?P<name>\d+)/', 'test'), def test(request, name): html = it
The following code: class MyClass(): def test(self): self.__x = 0 def __setattr__(self, name, value):
I need some like this: module One def test; puts 'Test One'; end end
How can it be that this test case import unittest class PropTest(unittest.TestCase): def test(self):
Assume I have the following ; def test(): while 1: a = b time.sleep(60)
On Rails 2.3.2 I'm trying to test a view in a functional test def
def start_test(request): os.system('echo Starting emulator...') os.system('./android-sdk-linux_x86/tools/emulator -avd testavd &') return HttpResponse(OK) Here is the
Under Python 3.1, when trying to run this code: from urllib import request def
this is my test code: def test_import_data(self): f = open('commend/fixtures/Book2.xls') postdata = {'datatype':'intonetwork','datafile':f} response

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.