By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,985 Members | 1,574 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,985 IT Pros & Developers. It's quick & easy.

A best approach to a creating specified http post body

P: n/a
Hi all, I'm rather new to python but not exaclty without programming
experience and not quite get best pyhton practices.
I have a following problem that it seems I cannot find a way to solve
correctly.

I need to build a special http post body that consists of :
name=value +\r\n strings.
Problem is that depending on operations the number of name,value
pairs can increase and decrease.
Values need to be initialized at runtime, so storing premade text
files is not possible.

The worst thing that some operations must be at beginning, so
dictionary approach with classes is kinda out.

Could you please provide some examples or descriptions on how you
would solve such problem ?
Thanks in advance.

May 18 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I need to build a special http post body that consists of :
name=value +\r\n strings.
Problem is that depending on operations the number of name,value
pairs can increase and decrease.
Values need to be initialized at runtime, so storing premade text
files is not possible.
I'm not completely understanding your problems here. Can you explain
why urllib.urlencode wouldn't work?
(http://docs.python.org/lib/module-urllib.html)

Thanks,
-Dave
May 18 '07 #2

P: n/a
Why not use scotch.recorder?

Dave Borne wrote:
>I need to build a special http post body that consists of :
name=value +\r\n strings.
Problem is that depending on operations the number of name,value
pairs can increase and decrease.
Values need to be initialized at runtime, so storing premade text
files is not possible.

I'm not completely understanding your problems here. Can you explain
why urllib.urlencode wouldn't work?
(http://docs.python.org/lib/module-urllib.html)

Thanks,
-Dave
--
Shane Geiger
IT Director
National Council on Economic Education
sg*****@ncee.net | 402-438-8958 | http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy
May 18 '07 #3

P: n/a
On May 18, 4:57 pm, "Dave Borne" <dbo...@gmail.comwrote:
I need to build a special http post body that consists of :
name=value +\r\n strings.
Problem is that depending on operations the number of name,value
pairs can increase and decrease.
Values need to be initialized at runtime, so storing premade text
files is not possible.

I'm not completely understanding your problems here. Can you explain
why urllib.urlencode wouldn't work?
(http://docs.python.org/lib/module-urllib.html)

Thanks,
-Dave
Hmm, I guess I meant something different by using "body"- I meant
request data part and not the thing sent in ulr string.

May 18 '07 #4

P: n/a
dz****@gmail.com wrote:
Hmm, I guess I meant something different by using "body"- I meant
request data part and not the thing sent in ulr string.
You should specify better what you need yes.

See, to send POST information in an http request, you can do the
following...
>>urllib2.urlopen(myurl, data=postbody)
....being postbody a string with the information you want to send, for
example "Hello world", "a=5&no=yes", or "\n\n\r\tMMalichorhoh829dh9ho2"

So, you need help building a post body, or you need building a string?

Regards,

--
.. Facundo
..
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/
May 18 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.