You are not logged in.

#1 2008-05-15 22:50:08

jeebusroxors
Member
Registered: 2005-10-26
Posts: 58
Website

Python multipart POST

http://pastebin.isawsome.net/pastebin.php?show=366

I'm trying to get a POST together to upload a local file to the tumblr api (tumblr.com). I keep getting Authorization Failed. I'm thinking it could be the header, or maybe a malformed URL (but that looks ok to me).

Anyways, code is above and below. I can't seem to find much documentation, so I figured I'd give the ol' BBS a shot.


def upvid(self):
                password = self.password
                email = self.email
                BOUNDARY = 'bOn3dkjlDr3Y'
                CRLF = '\r\n'
                files = '/home/dude/warn.wav'
                f=file('/home/dude/warn.wav')

                fvalue = f.read()
                ctype = mimetypes.guess_type(files)
                L = []
                L.append('--' + BOUNDARY)
                L.append('Content-Disposition: form-data; name="files"; filename="%s"' % (files))
                L.append('Content-Type: %s' %(ctype[0]))
                L.append('')
                L.append(fvalue)
                L.append('--' + BOUNDARY + '--')
                L.append('')

                #body = CRLF.join(L)
                body = ''.join(L)
                values =  {
                        'data' : body,
                        'type' : 'audio',
                        'password' : self.password,
                        'email' : self.email
                        }
                values=urllib.urlencode(values)

                content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
                h = httplib.HTTPConnection(self.url)
                headers = {'Content-Type': content_type }

                h.follow_all_redirects = True
                h.request('POST', '/api/write', values, headers)

                print values

                res = h.getresponse()
                print res.status, res.reason, res.read()

There's no place like 127.0.0.1

Offline

#2 2008-05-17 10:36:55

gnud
Member
Registered: 2005-11-27
Posts: 182

Re: Python multipart POST

Offline

#3 2008-05-17 13:03:27

jeebusroxors
Member
Registered: 2005-10-26
Posts: 58
Website

Re: Python multipart POST

That's what this is. Am I missing something obvious?


There's no place like 127.0.0.1

Offline

#4 2008-05-17 19:24:29

kumico
Member
Registered: 2007-09-28
Posts: 224
Website

Re: Python multipart POST

the code seems fine at a quick glance,
i checked using a web browser(GET) and it returns the same thing regardless of what input or lack thereof
i'm going to guess this is a problem with tumblr

Offline

Board footer

Powered by FluxBB