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)
Decode urlencoded string from the EG webserver
- Bitmonster
- Site Admin
- Posts: 2239
- Joined: Mon Feb 06, 2006 10:28 pm
Re: Decode urlencoded string from the EG webserver
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]
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!
- Bitmonster
- Site Admin
- Posts: 2239
- Joined: Mon Feb 06, 2006 10:28 pm
Re: Decode urlencoded string from the EG webserver
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!
Re: Decode urlencoded string from the EG webserver
Thanx, Bitmonster!
It works like a charm! I also rewrote the scripts to use payload instead (I had missed that feature)!
It works like a charm! I also rewrote the scripts to use payload instead (I had missed that feature)!
Re: Decode urlencoded string from the EG webserver
Another area I haven't played with, looks like I need to start!