Decode urlencoded string from the EG webserver

Do you have questions about writing plugins or scripts in Python? Meet the coders here.

Decode urlencoded string from the EG webserver

Postby Alink » Thu Mar 20, 2008 1:19 pm

Hi guys!

I'm trying to capture a string from a http request to the EG webserver.

As far as I can see there is no support for POST requests, only GET. Therefore I have to URLEncode the string before appending it to the request.

I capture the event HTTP.* and get the string from eg.event.suffix. All OK so far, except for the encoding since EG doesn't seem to automatically decode the string upon recieving it.

Now, beeing a Python n00b I wonder: is there an easy way to decode an URLEncoded string in the Python script?


(The string is a path+file that I want to send on to Media Player Classic)
Alink
 
Posts: 12
Joined: Mon Dec 10, 2007 6:23 pm

Re: Decode urlencoded string from the EG webserver

Postby Bitmonster » Thu Mar 20, 2008 4:09 pm

This should be possible with urllib.

import urllib
path = urllib.unquote(data)
...or...
path = urllib.unquote_plus(data)

But actually this should be seen as a bug of the webserver plugin. Of course it should do it itself before initiating the event. I will look into it later.

BTW:
You shouldn't use the event to transfer data. The event.payload is meant for such purposes. Make the URL by putting the pieces together with the "&" sign, like:
http://localhost/index.html?myEvent&C:\whatever\
(with right encoding it should actually look like:
http://localhost/index.html?myEvent&C%3A%5Cwhatever%5C
)
and you get always the event "myEvent" and the path as eg.event.payload[0]
Please post software-related questions in the forum - PMs will only be answered, if really private, thanks!
User avatar
Bitmonster
Site Admin
 
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Re: Decode urlencoded string from the EG webserver

Postby Bitmonster » Thu Mar 20, 2008 6:27 pm

0.3.6.1327 should decode the event and payload right.
Please post software-related questions in the forum - PMs will only be answered, if really private, thanks!
User avatar
Bitmonster
Site Admin
 
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Re: Decode urlencoded string from the EG webserver

Postby Alink » Fri Mar 21, 2008 4:12 pm

Thanx, Bitmonster!

It works like a charm! I also rewrote the scripts to use payload instead (I had missed that feature)!
Alink
 
Posts: 12
Joined: Mon Dec 10, 2007 6:23 pm

Re: Decode urlencoded string from the EG webserver

Postby CollinR » Fri Mar 21, 2008 5:52 pm

Another area I haven't played with, looks like I need to start!
CollinR
Experienced User
 
Posts: 265
Joined: Tue Sep 05, 2006 7:16 am
Location: Oklahoma


Return to Coding Corner

Who is online

Users browsing this forum: No registered users and 2 guests