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

  • Home
  • SEARCH
  • 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 8209003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:34:14+00:00 2026-06-07T09:34:14+00:00

I have VMware setup for testing. I create one user abc/abc123 to access the

  • 0

I have VMware setup for testing. I create one user abc/abc123 to access the Org url “http://localhost/cloud/org/MyOrg”. I want to access the RestAPI of the VCloud. I tried with RestClient plugin in firefox. Its working fine.

Now I tried with python code.

url = 'https://localhost/api/sessions/'
req = urllib2.Request(url)
base64string = base64.encodestring('%s:%s' % ('abc@MyOrg', 'abc123'))[:-1]
authheader =  "Basic %s" % base64string
req.add_header("Authorization", authheader)
req.add_header("Accept", 'application/*+xml;version=1.5')

f = urllib2.urlopen(req)
data = f.read()
print(data)

This is the code i get from stackoverflow. But for my example its give “urllib2.HTTPError: HTTP Error 403: Forbidden” Error.

I also tried HTTP authentication for the same.

  • 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-07T09:34:15+00:00Added an answer on June 7, 2026 at 9:34 am

    After doing some googling I found the solution from the post https://stackoverflow.com/a/6348729/243031. I change the code for my usability. I am posting the answer because if some one has same error then he will get the answer directly.

    My change code is:

    import urllib2
    import base64
    
    # make a string with the request type in it:
    method = "POST"
    # create a handler. you can specify different handlers here (file uploads etc)
    # but we go for the default
    handler = urllib2.HTTPSHandler()
    # create an openerdirector instance
    opener = urllib2.build_opener(handler)
    # build a request
    url = 'https://localhost/api/sessions'
    request = urllib2.Request(url)
    # add any other information you want
    base64string = base64.encodestring('%s:%s' % ('abc@MyOrg', 'abc123'))[:-1]
    authheader =  "Basic %s" % base64string
    request.add_header("Authorization", authheader)
    request.add_header("Accept",'application/*+xml;version=1.5')
    
    # overload the get method function with a small anonymous function...
    request.get_method = lambda: method
    # try it; don't forget to catch the result
    try:
        connection = opener.open(request)
    except urllib2.HTTPError,e:
        connection = e
    
    # check. Substitute with appropriate HTTP code.
    if connection.code == 200:
        data = connection.read()
        print "Data :", data
    else:
        print "ERRROR", connection.code
    

    Hope this will help some one who want to send POST request without the data.

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

Sidebar

Related Questions

I have access to a virtual machine via vmware client and want to do
I have a interesting problem, my script uses ssh to access my vmware server
I have recently setup a vmware instance with hadoop on my windows 7 machine.
I have a virtual machine running windows xp inside a vmware instance. How do
Have deployed numerous report parts which reference the same view however one of them
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
What is the simplest/most-streamlined setup for testing apps in all of todays browsers? Safari
i have installed TFS 2010 in a 2 server setup with an App Tier
We have a VMWare image running a gforge instance in our local network. We
I have Riak (1.0.2) installed in my VMWare Workstation running Ubuntu Linux Natty. It's

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.