Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango: Reading FileField Contents Immediately After Save
    text
    copied!<p>I have a model form with a file field on it. I have a post_save signal attached to the model so that I can then pass the uploaded file on to a 3rd-party via a web service (using <a href="https://fedorahosted.org/suds/" rel="nofollow noreferrer">Suds</a>). The web service call is dying when I try to pass it the file contents: it throws "UnicodeDecodeError: 'ascii' codec can't decode byte . . . " (much like in <a href="https://stackoverflow.com/questions/2953651/python-unicode-decode-error-suds">this SO question</a>).</p> <p>The thing I don't get: when I dump out the file contents to screen during my signal call, it looks like a mess of badly-encoded garbage:</p> <pre><code>åÉe Qçú&gt;↑ Åû½ΣΘ⌐v^τ  F,K╪Y&lt;▲î°bαⁿ╡ê5  ╜ù  sö╛Aî▲ƒF|04∙f╛@╙We⌡  ╤â╩_α↑└ƒ∙│ßï(è═|←⌂┌▒■µ'£─♂  ¢V↓ⁿq_;εδ▼εb&lt;í╜ƒÅΩN00τó╛‼¥U╫Z─)?¬∞┐Γ╠C4ä▬Il☼Jº╚J╥Ñ├¿öÆi2═♂ïσNù&amp;▐╤╡╔ΩIêµ╬]└@Üα╒→║¶\⌐UÑ╬çµ∟h⌂¼┘ë¢←↕╚↔ùα▌.¢d╖Y¡,♫½qÆ~╞äLX┬ä[┬2≥¥í=&lt;ß▼]Hⁿ↕!b÷ ñÑU┌M╥╦m¼'½ù'∞"'£└►oêu↓q┘ôÉ&gt;i_÷αµ0♥k§w▒c╠═╬6╙N2▀!)`► </code></pre> <p>when I grab the same object via the command line and call the exact same method on it, it all looks nicely encoded:</p> <pre><code>\x00F,K\xd8Y&lt;\x1e\x8c\xf8b\xe0\xfc\xb5\x885\xff\x00\xbd\x97\xff\x00s\x07\x94\xbeA\x8c\x1e\x9fF|04\xf9f\xbe@\xd3We\xf5\xff\x00\xd1\x83\xca_\xe0\x18\xc0\x9f\xf9\xb3\xe1\x8b(\x8a\xcd|\x1b\x7f\xda\xb1\xfe\xe6\'\x9c\xc4\x0b\xff\x00\x9bV\x19\x07\xfcq_;\xee\xeb\x1f\xeeb&lt;\xa1\xbd\x9f\x8f\xeaN00\xe7\xa2\xbe\x13\x9dU\xd7Z\xc4)?\xaa\xec\xbf\xe2\xccC4\x84\x16Il\x0fJ\xa7\xc8J\xd2\xa5\xc3\xa8\x94\x92i2\xcd\x0b\x8b\xe5N\x97&amp;\xde\xd1\xb5\xc9\xeaI\x88\xe6\xce]\xc0@\x9a\xe0\xd5\x1a\xba\x14\\\xa9U\xa5\xce\x87\xe6\x1ch\x7f\xac\xd9\x89\x9b\x1b\x12\xc8\x1d\x97\xe0\xdd.\x9bd\xb7Y\xad,\x0e\xabq\x92~\xc6\x84LX\xc2\x84[\xc22\xf2\x9d\xa1=&lt;\xe1\x1f]H\xfc\x12!b\xf6\x00\xa4\xa5U\xdaM\xd2\xcbm\xac\'\xab\x97\'\xec"\'\x9c\xc0\x10o\x88u\x19q\xd9\x93\x90&gt;i_\xf6\xe0\xe60\x03k\x15w\xb1c\xcc\xcd\xce6\xd3N2\xdf!)`\x10\nB\x8a\xaes\x13\xad\xd4a\x19\xa7p?\xff\xd9' </code></pre> <p>What's happening between the two steps and how can I get the proper contents back? Grabbing a second version of the object during my signal just gives me back the badly-encoded mess again. N.B., this is happening on Windows.</p>
 

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