gesomax / httplib2

Automatically exported from code.google.com/p/httplib2
0 stars 0 forks source link

Using urllib2 for a POST fail with basecamp #22

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
1.Working example with curl
2.Failing example with urllib2

"""
curl -v -H "Accept: application/xml" -H "Content-Type: 
application/xml" -u 
***:*** -L -d 
"<request><entry><project-id>***</project-id><person-id>***</person-id><date>200
80113</date><hours>1.0</hours><description>jabberbot</description></entry></requ
est>" 
http://electronlibre.projectpath.com/projects/1554720/time/save_entry"""

people_id = 911949
import urllib2
import base64
base64string = base64.encodestring('%s:%s' % ("***", "***"))
#headers = 
{'Accept': 'application/xml', 'Content-Type':'application/xml', 
"Authorization":"Basic %s" % 
base64string}
entry = 
str("<request><entry><project-id>***</project-id><person-id>***</person-id><date
>20080113</date><hours>1.0</hours><description>jabberbot</description></entry></
request>")

opener = urllib2.build_opener()
import urllib
#v = {'request':entry}
#entry = urllib.urlencode(v)
r = 
urllib2.Request('http://electronlibre.projectpath.com/time/save_entry', 
data=entry)
#r = urllib2.Request('http://127.0.0.1:8000/test/', data=entry)
r.add_header('Content-Type', 'application/xml')
r.add_header('Accept', 'application/xml')
#r.add_header('Content-length', len(entry)+2)
r.add_header('Authorization', 'Basic %s' % base64string)
try:
    print opener.open(r).read()
except urllib2.HTTPError, e:
    print e
    print "Request failure"

--------------------

The python fail because the data entry become amputed of these two last 
characters. If I had two space at the end of the entry string, It 
worked...

Can you reproduce it?

Original issue reported on code.google.com by batiste....@gmail.com on 27 Mar 2008 at 3:41

GoogleCodeExporter commented 8 years ago
Sorry, this project is 'httplib2' not 'urllib2'. Urllib2 is part of the Python
standard library and you will have to file a bug there.

Original comment by joe.gregorio@gmail.com on 27 Mar 2008 at 4:42

GoogleCodeExporter commented 8 years ago
Ho... sorry for the mistake

Original comment by batiste....@gmail.com on 28 Mar 2008 at 8:44