Posting an image the using python and pycurl

import os, sys

import pycurl

USER_AGENT = 'Mozilla/4.0 (compatible; MSIE 6.0)'

loginurl = ""

# Class which holds a file reference and the read callback

class FileReader:

    def __init__(self, fp):

        self.fp = fp

    def read_callback(self, size):


# Check commandline arguments

if len(sys.argv) < 3:

    print "Usage: %s
% sys.argv[0]

    raise SystemExit

servicetype = sys.argv[1]

filename = sys.argv[2]

itemname = sys.argv[3]

username = sys.argv[4]

password = sys.argv[5]

if not os.path.exists(filename):

    print "Error: the file '%s' does not exist" % filename

    raise SystemExit

# Initialize pycurl

c = pycurl.Curl()

# Request login page

c.setopt(pycurl.USERAGENT, USER_AGENT)

c.setopt(pycurl.FOLLOWLOCATION, 1)

#c.setopt(pycurl.WRITEFUNCTION, dev_null.write)

c.setopt(pycurl.COOKIEFILE, '')

c.setopt(pycurl.URL, loginurl + '?username=' + username + '&password=' + password)


# Create the item

c.setopt(c.POST, 1)

c.setopt(c.URL, "" + servicetype + "@core/create_item")

c.setopt(c.HTTPPOST, [("file", (c.FORM_FILE, filename)),("name", itemname),("username_override", "ajaxmmo")])

c.setopt(c.VERBOSE, 1)



My Linux Experience (update)

I have been a linux user since 1996, this started with Slackware 2.6,

I have configured xinitrc, lilo, grub, xconfig, fstab, etc..

Then with Slackware 7 I installed Apache, PHP, MySql, I made bash files, c++ applications and perl scripts.

I then had relatively old hardware compared to the time, so I spent a lot of time reconfiguring the kernel and recompiling it.

I created fvwm configs for my machine which ran very fast compared to other window managers.

From slackware I moved on to Debian, which still involved configuring the xconf file, more recently with debian
I installed applications such a compiz, for 3D window management.

My text editors include eclipse, vim, emacs, nano or gedit.

I have made Make files, installed the LAMP stack made programs in php using mySQL.

I have configured Apache, lighttpd, nginx, php. Have used apache, lighttpd and nginx for virtual hosting.

I have programmed Ruby on Rails and set up mySQL.

I new use Ubuntu and am a competent CLI user.
I have also installed Gentoo, Sabayon and FreeBSD.

I have looked into Mono for c# development but have a preference for Python and django.

I have installed svn, used svn and cvs.

The latest example of my python can be seen at

I have remote accessed other Linux machines using ssh (including X11 redirection) and VNC.

I have used web control panels such as cpanel and the django panel.