views:

31

answers:

1

I am currently implementing code to call out to an API where the post request body needs to contain several columns of data in csv format.

e.g.

Col1, Col2, Col3

1, 2, 3

4, 5, 6

etc, with the content type header is set to 'text/csv'

How do I directly write to the request body?

I have a coworker who is doing the same thing as I am in Java and the Apache httpclient lib simply has a setRequestBody method.

Is there something similar in httplib, urllib (1,2) or pyCurl? Thanks.

+2  A: 

Any HTTP client will give you some way to set the request body. For example, httplib.HTTPConnection.request takes an optional body parameter that allows you to pass request data. Same with urllib2.urlopen (there it's called data). I've never used PycURL myself but it definitely provides some way to include a body in the request.

David Zaslavsky