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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:19:36+00:00 2026-05-19T12:19:36+00:00

When using the following code to connect to the toggl api I connect and

  • 0

When using the following code to connect to the toggl api I connect and am authorised just fine.

username = token
password = 'api_token'
url = 'http://www.toggl.com/api/v3/tasks.json'

req = urllib2.Request(url)
auth_string = base64.encodestring('%s:%s' % (username, password))
req.add_header("Authorization", "Basic %s" % auth_string)
f = urllib2.urlopen(req)
response = f.read()

When I try to start a new task I have to send data in json format. To test, I created my json object and added the data to my Request object

data = simplejson.dumps({
    'task':{
        'duration': 1,
        'billable': True,
        'start': '2010-02-12T16:19:45+02:00',
        'description': 'This is a test task',
    }
})
req = urllib2.Request(url, data)

But now the only response I recieve is “urllib2.HTTPError: HTTP Error 400: Bad Request”. Can someone please point me to where I am going wrong?

  • 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-05-19T12:19:37+00:00Added an answer on May 19, 2026 at 12:19 pm

    According to the API documentation, you’re missing at least a header. Try:

    req = urllib2.Request(url, data, {"Content-type": "application/json"})
    

    If that’s not enough, try using urllib.urlencode on data. If that’s still not enough, add a user:password to the request, like in the API example.

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

Sidebar

Related Questions

I am using following PHP code to connect to MS Access database: $odb_conn =
I am using following code to connect to MySql Db but it gives error.
I am using the following C# code to connect to active directory and validate
I am trying to connect database.sdf on same director. Using following code but gives
I'm using the following code to connect to remote machine using WMI: ConnectionOptions connOptions
I am trying to connect to sql server using php using following code: $myServer
I am using the following code to establish a HTTP connection and read data:
I am using the following code for create a button. It is working fine.
Using the following code I get a nice formatted string: Request.QueryString.ToString Gives me something
I'm using the following code to query a database from my jsp, but I'd

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.