urllib2 problem, data param not working?

Discussion in 'Python' started by Gabriel Rossetti, Mar 31, 2009.

  1. Hello everyone,

    I am having a problem with urllib2, when I do this :

    post = urllib.urlencode(post)
    request = urllib2.Request(url, post)
    response = urllib2.urlopen(request)

    or this :

    post = urllib.urlencode(post)
    response = urllib2.urlopen(url, post)

    or this :

    post = urllib.urlencode(post)
    request = urllib2.Request(url)
    response = urllib2.urlopen(request, post)

    it doesn't work, it's like if the post params weren't added, and if I do
    this :

    post = urllib.urlencode(post)
    request = url + '?' + post
    response = urllib2.urlopen(request)

    it works as expected, can anyone explain what is going on? I know that
    if I don't add the data ('post' in my case) param it uses an HTTP GET,
    could that be why it works when I add them manually?

    Thank you,
    Gabriel
     
    Gabriel Rossetti, Mar 31, 2009
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Geathaa
    Replies:
    2
    Views:
    907
    Geathaa
    Jul 30, 2003
  2. Tjerk Wolterink

    XSL:param data-types

    Tjerk Wolterink, Nov 20, 2004, in forum: XML
    Replies:
    1
    Views:
    852
    Tjerk Wolterink
    Nov 20, 2004
  3. Josef Cihal
    Replies:
    0
    Views:
    1,287
    Josef Cihal
    Sep 5, 2005
  4. =?ISO-8859-1?Q?Gregory_Pi=F1ero?=

    urllib2 - My POST Request just isn't working right

    =?ISO-8859-1?Q?Gregory_Pi=F1ero?=, Feb 1, 2006, in forum: Python
    Replies:
    1
    Views:
    3,991
    Don't Code Faster Than You Can See
    Feb 1, 2006
  5. Eric Nieuwland
    Replies:
    8
    Views:
    694
    =?ISO-8859-1?Q?Gregory_Pi=F1ero?=
    Feb 1, 2006
  6. ectoplasm
    Replies:
    12
    Views:
    929
    Zorro
    Jul 28, 2005
  7. Alex Borghgraef
    Replies:
    3
    Views:
    564
    Alex Borghgraef
    Feb 28, 2012
  8. Dave
    Replies:
    5
    Views:
    1,207
    John Bokma
    Apr 26, 2011
Loading...