Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > url.encore/quote

Reply
Thread Tools

url.encore/quote

 
 
zowtar
Guest
Posts: n/a
 
      06-26-2008
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?
 
Reply With Quote
 
 
 
 
ianitux
Guest
Posts: n/a
 
      06-26-2008
On 26 jun, 12:53, zowtar <(E-Mail Removed)> 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'
 
Reply With Quote
 
 
 
 
John Salerno
Guest
Posts: n/a
 
      06-26-2008
"zowtar" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.


 
Reply With Quote
 
ianitux
Guest
Posts: n/a
 
      06-26-2008
On 26 jun, 15:53, "John Salerno" <(E-Mail Removed)> wrote:
> "zowtar" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
> > 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'
 
Reply With Quote
 
John Salerno
Guest
Posts: n/a
 
      06-26-2008
"ianitux" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments