Note that there are some explanatory texts on larger screens.

plurals
  1. POPython: urllib.urlencode is escaping my stuff *twice*
    primarykey
    data
    text
    <p>... but it's not escaping it the same <em>way</em> twice.</p> <p>I'm trying to upload ASCII output from gpg to a website. So, the bit I've got, so far, just queries the table, shows me the data it got, and then shows it to me after it encodes it for a HTTP POST request:</p> <pre><code>cnx = connect() sql = ("SELECT Data FROM SomeTable") cursor = cnx.cursor() cursor.execute(sql) for (data) in cursor: print "encoding : %s" % data postdata = urllib.urlencode( { "payload" : data } ) print "encoded as %s" % postdata </code></pre> <p>... but what I get is:</p> <pre><code>encoding : -----BEGIN PGP MESSAGE----- Version: GnuPG v1.4.12 (GNU/Linux) .... etc... encoded as payload=%28u%27-----BEGIN+PGP+MESSAGE-----%5CnVersion%3A+GnuPG+v1.4.12+... etc ... </code></pre> <p>The part to notice is that the newlines aren't getting turned into %0A, like I'd expect. Instead, they're somehow getting escaped into "\n", and then the backslashes are escaped to %5C, so a newline becomes "%5Cn". Even stranger, the data gets prepended with <em>%28u%27</em>, which comes out to "<em>(u'</em>".</p> <p>Oddly, if I just do a basic test with:</p> <pre><code>data = "1\n2" print data print urllib.urlencode( { "payload" : data } ) </code></pre> <p>I get what I expect, newlines turn into %0A...</p> <pre><code>1 2 payload=1%0A2 </code></pre> <p>So, my hunch is that the data element returned from the mysql query isn't the same kind of string as my literal "1\n2" (maybe a 1-element dict... dunno), but I don't have the Python kung-fu to know how to inspect it.</p> <p>Anybody know what's going on, here, and how I can fix it? If not, any suggestions for how to POST this via HTTP with everything getting escaped properly?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload