url.encore/quote

Discussion in 'Python' started by zowtar, Jun 26, 2008.

  1. zowtar

    zowtar Guest

    urlencode({'page': i, 'order': 'desc', 'style': 'flex power'})
    return:
    page=1&order=desc&style=flex+power

    but I want:
    page=1&order=desc&style=flex%20power

    and url.quote don't put the &'s and ='s
    any idea guys?
     
    zowtar, Jun 26, 2008
    #1
    1. Advertising

  2. zowtar

    ianitux Guest

    On 26 jun, 12:53, zowtar <> wrote:
    > urlencode({'page': i, 'order': 'desc', 'style': 'flex power'})
    > return:
    > page=1&order=desc&style=flex+power
    >
    > but I want:
    > page=1&order=desc&style=flex%20power
    >
    > and url.quote don't put the &'s and ='s
    > any idea guys?


    Hi, a quick solution can be this one, or maybe you can do something
    similar

    >>> import string, urllib
    >>> a = urllib.urlencode({'page': 'i', 'order': 'desc', 'style': 'flex power'})
    >>> a.replace('+','%20')

    'style=flex%20power&page=i&order=desc'
     
    ianitux, Jun 26, 2008
    #2
    1. Advertising

  3. zowtar

    John Salerno Guest

    "zowtar" <> wrote in message
    news:...
    > urlencode({'page': i, 'order': 'desc', 'style': 'flex power'})
    > return:
    > page=1&order=desc&style=flex+power
    >
    > but I want:
    > page=1&order=desc&style=flex%20power
    >
    > and url.quote don't put the &'s and ='s
    > any idea guys?


    urlencode() uses quote_plus() when it creates a URL, which is why you are
    getting the plus signs. Unfortunately I don't have Python at work, so I
    can't try this, but maybe do:

    quote(urlencode({'page': i, 'order': 'desc', 'style': 'flex power'}))

    and see if that works? I'm not sure if quote() will convert the %20 into +,
    though, but it may.
     
    John Salerno, Jun 26, 2008
    #3
  4. zowtar

    ianitux Guest

    On 26 jun, 15:53, "John Salerno" <> wrote:
    > "zowtar" <> wrote in message
    >
    > news:...
    >
    > > urlencode({'page': i, 'order': 'desc', 'style': 'flex power'})
    > > return:
    > > page=1&order=desc&style=flex+power

    >
    > > but I want:
    > > page=1&order=desc&style=flex%20power

    >
    > > and url.quote don't put the &'s and ='s
    > > any idea guys?

    >
    > urlencode() uses quote_plus() when it creates a URL, which is why you are
    > getting the plus signs. Unfortunately I don't have Python at work, so I
    > can't try this, but maybe do:
    >
    > quote(urlencode({'page': i, 'order': 'desc', 'style': 'flex power'}))
    >
    > and see if that works? I'm not sure if quote() will convert the %20 into +,
    > though, but it may.


    This is what quot do.

    >>> import urllib
    >>> u = urllib
    >>> u.quote(u.urlencode({'page': 'i', 'order': 'desc', 'style': 'flex power'}))

    'style%3Dflex%2Bpower%26page%3Di%26order%3Ddesc'
     
    ianitux, Jun 26, 2008
    #4
  5. zowtar

    John Salerno Guest

    "ianitux" <> wrote in message
    news:...
    >> and see if that works? I'm not sure if quote() will convert the %20 into
    >> +,
    >> though, but it may.

    >
    > This is what quot do.
    >
    >>>> import urllib
    >>>> u = urllib
    >>>> u.quote(u.urlencode({'page': 'i', 'order': 'desc', 'style': 'flex
    >>>> power'}))

    > 'style%3Dflex%2Bpower%26page%3Di%26order%3Ddesc'


    I know quote will convert spaces to %20, just wasn't sure if it would
    explicitly convert + to %20.

    But it seems the output isn't what the OP wants anyway, because he wanted
    the & and = symbols.
     
    John Salerno, Jun 26, 2008
    #5
    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. Replies:
    3
    Views:
    13,433
  2. Stimp
    Replies:
    2
    Views:
    2,334
    Stimp
    Sep 20, 2006
  3. Eric Layman
    Replies:
    3
    Views:
    665
    Rad [Visual C# MVP]
    Apr 14, 2007
  4. Replies:
    6
    Views:
    462
    Stefan Ram
    Jun 15, 2008
  5. Martin Rinehart

    Cross-Browser Client Size, Encore

    Martin Rinehart, Dec 22, 2008, in forum: Javascript
    Replies:
    2
    Views:
    128
    dhtml
    Jan 2, 2009
Loading...

Share This Page