【问题标题】:Error trying to run first python script on IIS尝试在 IIS 上运行第一个 python 脚本时出错
【发布时间】:2013-01-08 11:45:34
【问题描述】:

我遵循了如何为 IIS 设置 Python 的步骤: Python on IIS: how?

但是当我编写脚本并尝试运行它时,它在第一行就失败了。我收到此错误消息:

HTTP 错误 502.2 - Bad Gateway 指定的 CGI 应用程序 由于未返回完整的 HTTP 标头集而导致行为不端。这 它确实返回的标题是“文件 “C:\Development\Python\helloworld.py”,第 1 行打印 'Content-Type: text/plain' ^ SyntaxError: invalid syntax ".

这是我对 python 的第一次尝试。出了什么问题?

【问题讨论】:

  • 你用的是哪个python版本?如果您使用的是 python 3,则需要括号:例如,print('Content-Type: text/plain')
  • 是的,它是 3。那么每个打印语句都需要括号吗? 3 的语法有什么变化?
  • 在下面查看我的评论。如果它满足您的问题,请随时接受。

标签: iis python-3.x


【解决方案1】:

所以你的例子helloworld.py需要改成:

print('Content-Type: text/plain')
print('')
print('Hello, world!')

Python 3 将 print 更改为使用函数调用语法(可以在 python 2 中使用)。

【讨论】:

  • 它只对我有用:在我的代码顶部使用 print(),我不需要使用 print('Content-Type: text/plain')
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-09
  • 1970-01-01
  • 2017-02-06
  • 1970-01-01
  • 2023-02-08
  • 2013-11-09
相关资源
最近更新 更多