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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:21:22+00:00 2026-06-14T00:21:22+00:00

I have a working GET using 2-legged oauth2 in python. Here is the WORKING

  • 0

I have a working GET using 2-legged oauth2 in python. Here is the WORKING GET code:

the imports:

import oauth2 
import urllib #for url-encode
import urllib2 #for getting and receiving data from server
import time #Unix timestamp import oauth2

the call:

resourceUrl = "https://test.mysite:8443/ess/scheduleapi/v1/people"
request = build_request(resourceUrl,'GET')
u = urllib2.urlopen(request.to_url())
people_data = u.read()

the function to build the request:

def build_request(url, method):
    params = {                                            
        'oauth_version': "1.0",
        'oauth_nonce': oauth2.generate_nonce(),
        'oauth_timestamp': int(time.time())
    }
    consumer = oauth2.Consumer(key='mykey',secret='mysecret')
    params['oauth_consumer_key'] = consumer.key
    req = oauth2.Request(method=method, url=url, parameters=params)
    signature_method = oauth2.SignatureMethod_HMAC_SHA1()
    req.sign_request(signature_method, consumer, None)
    return req
#end build_request

So, I thought I could copy the part of the GET that I thought I’d need, plus combine it with the syntax I got off of some urllib2 documentation, and cook up a working POST. Not so. Keep in mind I have the same imports and the same build_request function. Here is the BROKEN POST code. Please advise!

the call:

myurl =  "https://test.mysite:8443/ess/scheduleapi/v1/people" 
myaction = 'POST'
myxml = somexmlIalreadygenerated
person_added, err = post_or_put_me(myaction,myxml,myurl)

the function to POST:

def post_or_put_me(action,xml,url)
    request = build_request(url,action) # use same header-generating code as GET did?
    post_data = urllib.urlencode(xml)
    req = urllib2.Request(request,post_data)
    try:
        u = urllib2.urlopen(req)
        post_or_put_returned_data = u.read()
        print 'LENGTH  :', len(post_or_put_returned_data)
        print 'DATA    :', post_or_put_returned_data
    except urllib2.HTTPError, e:
        server_error = 'HTTPError = ' + str(e.code)
    except urllib2.URLError, e:
        server_error = 'URLError = ' + str(e.reason)
    except httplib.HTTPException, e:
        server_error = 'HTTPException'
    except Exception:
        import traceback
        server_error = 'generic exception: ' + traceback.format_exc()
    #endtry

    if server_error:
        err_msg = server_error
    else:   
        succ_msg = 'you had a successful post or put'
    #endif

    return succ_msg, err_msg
#end post_or_put_me

Here’s my second attempt:

def post_or_put_me(action,xml,url):
    myrequest = build_request(url,'POST')

    CONSUMER_KEY = 'admin_access'
    CONSUMER_SECRET = 'xxxxxxxxxx' 
    consumer = oauth2.Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET)
    token = oauth2.Token(key=CONSUMER_KEY, secret=CONSUMER_SECRET)
    client = oauth2.Client(consumer, token)
    resp, content = client.request(
        url,
        method=action,
        body=urllib.urlencode(str(xml)),
        headers= myrequest.headers,
        force_auth_header=True,
    )
    print 'resp, content are', resp, content
  • 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-14T00:21:23+00:00Added an answer on June 14, 2026 at 12:21 am

    Here is ACTUAL, WORKING code of how I got my POST or PUT to work, kindly supplied by Wes Barnes from Echo360 Lecture Capture. I don’t want anyone else doing a 2-legged oauth POST/PUT to have to reinvent the wheel.

    import oauth2 as oauth
    import time
    import urllib2 as urllib
    
    echo_base_url = 'http://pilot.echo360.com/ess/scheduleapi/v1'
    
    consumer = oauth.Consumer(key ='xxxxx', secret='xxxx')
    client = oauth.Client(consumer)
    params = "<person><first-name>Jon</first-name><last-name>Doe</last-name><title>Super  Hero</title><email-address>jdoe17@echo360.com</email-address><block-alerts>false</block-alerts><time-zone>US/Eastern</time-zone><locale>en_US</locale><credentials><user-name>jdoe17@echo360.com</user-name><password>password</password></credentials><organization-roles><organization-role><organization-id>b1973c39-dc76-4cab-a4aa-3f9efd628df2</organization-id><role>role-name-admin</role></organization-role></organization-roles></person>"
    
    resp, content = client.request(
                    echo_base_url + "/people/",
                    method = "PUT",
                    body=params,
                    headers={'Content-type': 'application/xml'}
                    #force_auth_header=True
                    )
    print resp, content
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with MyFaces/Primefaces and I have a problem to get information using
I have trouble to get gluLookAt working. I have the following code which works
I am trying to get MSTest working with CruiseControl.Net. I currently have it working
I have been working on this for days but I don't get it so
I have a script that I'm trying to get working. Basically, what I'm trying
I have this simple example I can't seems to get working : MERGE INTO
I have a data access class that took me a while to get working.
I have a trouble trying to get this working. I have an Item model,
I have tried and failed to get this working. Basically I am trying to
I have an issue working with Microsoft.Build.BuildEngine which supposed to get fixed modifing my

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.