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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:51:15+00:00 2026-05-24T03:51:15+00:00

I tried to convert a php api code to python: This is the php

  • 0

I tried to convert a php api code to python:

This is the php code:

// Variables to Post
$local_file = "/path/to/file"; 
$file_to_upload = array(
 'file'=>'@'.$local_file, 
'convert'=>'1', 
'user'=>'YOUR_USERNAME', 
'password'=>'YOUR_PASSWORD'
); 

// Do Curl Request
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,'http://example.org/dapi.php'); 
curl_setopt($ch, CURLOPT_POST,1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $file_to_upload); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec ($ch); 
curl_close ($ch); 

// Do Stuff with Results
echo $result; 

And this is my Python Code:

url = 'http://example.org/dapi.php'
file ='/path/to/file'
datei= open(file, 'rb').read()

values = {'file' : datei ,
     'user' : 'username',
     'password' : '12345' ,
     'convert': '1'}

data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
the_page = response.read()

print the_page

It uploads my files but the response is an Error so that something has to be wrong with my python code. But I can´t see my mistake.

  • 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-24T03:51:16+00:00Added an answer on May 24, 2026 at 3:51 am

    After trying a lot of opportunities. I found my solution using pycurl:

    import pycurl
    import cStringIO
    
    url = 'http://example.org/dapi.php'
    file ='/path/to/file'
    
    
    print "Start"
    response = cStringIO.StringIO()
    c = pycurl.Curl()
    values = [('file' , (c.FORM_FILE,  file)),
          ('user' , 'username'),
          ('password' , 'password'),
          ('convert', '1')]
    
    
    c.setopt(c.POST, 1)
    c.setopt(c.URL,url)
    c.setopt(c.HTTPPOST,  values)
    #c.setopt(c.VERBOSE, 1)
    c.setopt(c.WRITEFUNCTION, response.write)
    c.perform()
    c.close()
    print response.getvalue()
    print "All done"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Tried this: $('.link').click(function(e) { $.getScript('http://www.google.com/uds/api?file=uds.js&amp;v=1.0', function() { $('body').append('<p>GOOGLE API (UDS) is loaded</p>'); }); return
Is there any PHP script to convert XML file to DTD. I tried a
I need to convert %F3%BE%AE%A2 to this char in PHP. When I tried using
I want to convert a primitive to a string, and I tried: myInt.toString(); This
Is there any python module to convert PDF files into text? I tried one
I need to convert a unix timestamp to a date object. I tried this:
Can someone convert below code to ASP format? <?php $data = ' [ {
This is part of my JSON file I obtain through the twitter API: text:Scientists
I have just come across this great API: http://ipinfodb.com/ip_location_api.php However, I would like to
i want to send a javascript array to php using jquery ajax. $.post(controllers/ajaxcalls/users.php, {

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.