0

this runs fine on my local machine, but as soon as I deploy it the service fails saying invalid syntax "for"

  data = {k: request.form[k] for k in request.form.iterkeys()}   
SyntaxError: invalid syntax

Appreciate the help on this, it's been a very long time since I did anything with Python and this one has got me stumped.

Martijn Pieters
  • 963,270
  • 265
  • 3,804
  • 3,187
AppHandwerker
  • 1,673
  • 12
  • 22

3 Answers3

2

As others have mentioned, this is probably a version issue. Try:

data = dict((k,request.form[k]) for k in request.form.iterkeys())
ebarr
  • 7,476
  • 1
  • 25
  • 38
1

The python version on your local machine might be different from the version you have on the server.

Yosi
  • 59
  • 3
0

Dict comprehensions are a relatively new addition to 2.x. Convert it to a genex that generates (key, value) pairs and pass it to the dict() constructor.

Ignacio Vazquez-Abrams
  • 740,318
  • 145
  • 1,296
  • 1,325