GET and POST

Discussion in 'Python' started by franck, Sep 11, 2003.

  1. franck

    franck Guest

    HI,

    this is my code
    params = {}

    params['fuseaction'] = '*****';
    params['user'] = '***';
    params['password'] = '**********';
    params['num_card'] = '******';
    params['date_of_birth'] = '****';

    params = urllib.urlencode(params)
    f = urllib.urlopen("http://bidule.com",params)
    print f.read()

    my contact tell me i must do a GET or fuseaction and POST for other param.

    i dont know how to do this and if its possible.
    someone tell me its ok to do that, but how in python?

    i dont unsderstand the different between GET and POST but i know how to code
    it separately.

    thx in advance.
     
    franck, Sep 11, 2003
    #1
    1. Advertising

  2. franck

    Jeremy Jones Guest

    * franck () wrote:
    > HI,
    >
    > this is my code
    > params = {}
    >
    > params['fuseaction'] = '*****';
    > params['user'] = '***';
    > params['password'] = '**********';
    > params['num_card'] = '******';
    > params['date_of_birth'] = '****';
    >
    > params = urllib.urlencode(params)
    > f = urllib.urlopen("http://bidule.com",params)



    According to the urllib documentation (I've never used urllib, only
    httplib), all you have to do is change:

    f = urllib.urlopen("http://bidule.com",params)
    to
    f = urllib.urlopen("http://bidule.com?%s" % params)

    Here is the example from the documentation for a GET (found at
    http://www.python.org/doc/current/lib/node415.html):

    >>> import urllib
    >>> params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
    >>> f = urllib.urlopen("http://www.musi-cal.com/cgi-bin/query?%s" % params)
    >>> print f.read()


    I haven't whether this works or not, so I take no responsibility for any
    damage caused by this code ;-)

    Jeremy Jones
     
    Jeremy Jones, Sep 11, 2003
    #2
    1. Advertising

  3. franck

    franck Guest

    i know how to do a GET.
    :) i have this example.
    my contact tell my i must do a get AND a post :/

    GET to fuse param et POST for the others.

    dont know how do that.

    "Jeremy Jones" <> a écrit dans le message news:
    ...
    > * franck () wrote:
    > > HI,
    > >
    > > this is my code
    > > params = {}
    > >
    > > params['fuseaction'] = '*****';
    > > params['user'] = '***';
    > > params['password'] = '**********';
    > > params['num_card'] = '******';
    > > params['date_of_birth'] = '****';
    > >
    > > params = urllib.urlencode(params)
    > > f = urllib.urlopen("http://bidule.com",params)

    >
    >
    > According to the urllib documentation (I've never used urllib, only
    > httplib), all you have to do is change:
    >
    > f = urllib.urlopen("http://bidule.com",params)
    > to
    > f = urllib.urlopen("http://bidule.com?%s" % params)
    >
    > Here is the example from the documentation for a GET (found at
    > http://www.python.org/doc/current/lib/node415.html):
    >
    > >>> import urllib
    > >>> params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
    > >>> f = urllib.urlopen("http://www.musi-cal.com/cgi-bin/query?%s" %

    params)
    > >>> print f.read()

    >
    > I haven't whether this works or not, so I take no responsibility for any
    > damage caused by this code ;-)
    >
    > Jeremy Jones
    >
     
    franck, Sep 11, 2003
    #3
  4. franck

    Brian Victor Guest

    franck wrote:
    > i know how to do a GET.
    >:) i have this example.
    > my contact tell my i must do a get AND a post :/
    >
    > GET to fuse param et POST for the others.


    Without knowing urllib, I would infer from the rest of the code that
    you'd want to do something like this:

    getparams['fuseaction'] = '*****'
    postparams['num_card'] = '*****'

    getparams = urllib.urlencode(getparams)
    postparams = urllib.urlencode(postparams) # may not be necessary
    f = urllib.urlopen("http://bidule.com?%s" % getparams, postparams)

    --
    Brian
     
    Brian Victor, Sep 11, 2003
    #4
  5. franck

    John J. Lee Guest

    Brian Victor <> writes:

    > franck wrote:
    > > i know how to do a GET.
    > >:) i have this example.
    > > my contact tell my i must do a get AND a post :/
    > >
    > > GET to fuse param et POST for the others.

    >
    > Without knowing urllib, I would infer from the rest of the code that
    > you'd want to do something like this:
    >
    > getparams['fuseaction'] = '*****'
    > postparams['num_card'] = '*****'
    >
    > getparams = urllib.urlencode(getparams)
    > postparams = urllib.urlencode(postparams) # may not be necessary
    > f = urllib.urlopen("http://bidule.com?%s" % getparams, postparams)


    It seems unlikely that that's what is required (but you never
    know...).

    If the OP can post the HTML or a link, it would be rather easier to
    say what the problem is!


    John
     
    John J. Lee, Sep 11, 2003
    #5
  6. franck

    Steve Holden Guest

    "franck" <> wrote in message
    news:l908b.1425$-net.net...
    > i know how to do a GET.
    > :) i have this example.
    > my contact tell my i must do a get AND a post :/
    >

    In which case your contact is likely talking through his or her hat. GET and
    POST are HTTP methods. In any given interaction the client can do either a
    GET or a POST (or one of a number of other methods: the operative word here
    is ONE).

    > GET to fuse param et POST for the others.
    >
    > dont know how do that.
    >

    I suspect what your contact means is that you have to provide the value of
    (I presume you mean) fuseaction encoded in the URL, and that the rest must
    be provided as POST data. This is a somewhat bizarre requirement (and their
    server is obviously not written in Python, but that's another thread ...).

    Try something like:

    params = {}

    params['user'] = '***';
    params['password'] = '**********';
    params['num_card'] = '******';
    params['date_of_birth'] = '****';

    params = urllib.urlencode(params)
    f = urllib.urlopen("http://bidule.com?fuseaction=*****",params)
    print f.read()

    and see if that works. If not, go back to your contact for further
    enlightenment. Do they mean two operations or just one?

    regards
    --
    Steve Holden http://www.holdenweb.com/
    Python Web Programming http://pydish.holdenweb.com/pwp/
     
    Steve Holden, Sep 11, 2003
    #6
    1. Advertising

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. Sridhar Hegde
    Replies:
    2
    Views:
    2,529
    Ajeetha Kumari
    Sep 13, 2004
  2. khawar
    Replies:
    2
    Views:
    1,415
    vMike
    Oct 28, 2003
  3. John Dalberg
    Replies:
    8
    Views:
    640
    John Dalberg
    Sep 23, 2004
  4. Mark Turney
    Replies:
    11
    Views:
    4,286
    dibeas
    Nov 13, 2006
  5. arnuld
    Replies:
    6
    Views:
    619
    arnuld
    Sep 5, 2007
Loading...

Share This Page