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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:03:27+00:00 2026-06-17T12:03:27+00:00

The following curl command works perfectly (private data anonymized): curl -X POST ‘https://api.twilio.com/2010-04-01/Accounts/abc/SMS/Messages.json’ \

  • 0

The following curl command works perfectly (private data anonymized):

curl -X POST 'https://api.twilio.com/2010-04-01/Accounts/abc/SMS/Messages.json' \
-d 'From=%2B14155551234' \
-d 'To=%2B17035551212' \
-d 'Body=This+is+a+test' \
-u foo:bar

How can I send out this exact same HTTPS POST request in the proper Python3.3 way? I don’t want to have to use anything other than Python 3.3’s standard library if I can avoid it (in other words, not using the twilio python module, or “requests”, or pycurl, or anything outside the plain vanilla Python 3.3 installation).

The preferred Python approach seems to keep evolving from version to version, the snippets I find by Googling never mention which version they’re using or don’t do the login part, the Python docs are full of “deprecated since 3.x” but never include code examples of the new way to do things….

If curl can do this so easily, so can standard Python 3.3. But how exactly is this supposed to be done now?

  • 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-17T12:03:28+00:00Added an answer on June 17, 2026 at 12:03 pm

    Here’s a version that works both on Python 2 and 3:

    import requests # pip install requests
    
    url = 'https://api.twilio.com/2010-04-01/Accounts/abc/SMS/Messages.json'
    r = requests.post(url, dict(
            From='+17035551212',
            To='+17035551212',
            Body='This is a test'), auth=('foo', 'bar'))
    
    print(r.headers)
    print(r.text) # or r.json()
    

    To make https post request with basic http authentication on Python 3.3:

    from base64 import b64encode
    from urllib.parse import urlencode
    from urllib.request import Request, urlopen
    
    user, password = 'foo', 'bar'
    url = 'https://api.twilio.com/2010-04-01/Accounts/abc/SMS/Messages.json'
    data = urlencode(dict(From='+17035551212', To='+17035551212', 
                          Body='This is a test')).encode('ascii')
    headers = {'Authorization': b'Basic ' +
            b64encode((user + ':' + password).encode('utf-8'))}
    cafile = 'cacert.pem' # http://curl.haxx.se/ca/cacert.pem
    response = urlopen(Request(url, data, headers), cafile=cafile)
    
    print(response.info())
    print(response.read().decode()) # assume utf-8 (likely for application/json)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following curl command works as expected: curl 'https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=myappid&client_secret=myclientsecret' I want to do the
I need a transformation of the following working curl command: curl --data-binary @data.txt http://www.example.com/request.asp
I have the following curl command that works perfectly from the windows command line:
I'm testing a REST post service with the following unix command: curl -d {begTime:2012-06-06
I'm trying to convert the following CURL: curl -X POST \ -H Content-Type: image/jpeg
when I get the following url with curl curl -D headers.http http://www.springerlink.com/index/10.1007/s00453-007-9157-8 the file
I'm trying to simply test my RESTful API with cURL. Using the following invocation:
What would the following cURL command look like as a generic (without cURL) http
How can I rewrite the following CURL command, so that it doesn't use the
I have a curl command: curl -u ${USER_ID}:${PASSWORD} -X GET 'http://blah.gso.woo.com:8080/rest/job-execution/job-details/${job_id}' The variable job_id

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.