尝试从 bash 运行 Python 脚本时出现奇怪的 HTML 文档类型错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37818409/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 14:46:37  来源:igfitidea点击:

Strange HTML doctype error when trying to run Python script from bash

pythonhtmlbashwget

提问by Connor Spangler

I have a bash script which is supposed to call a Python script stored on GitHub and run it with arguments:

我有一个 bash 脚本,它应该调用存储在 GitHub 上的 Python 脚本并使用参数运行它:

#!/bin/bash +x

wget https://github.place.otherplace.com/myrepo/repo_folder/blob/Python/pythonScript.py
chmod +x pythonScript.py
python pythonScript.py

I'm getting the following response: HTTP request sent, awaiting response... 200 OK Length: unspecified [text/html] Saving to: ‘DisputeSystem.py'

我收到以下响应:HTTP 请求已发送,正在等待响应... 200 OK 长度:未指定 [text/html] 保存到:'DisputeSystem.py'

 0K .......... .......... .......... ........               795K=0.05s

2016-06-14 11:08:24 (795 KB/s) - ‘pythonScript.py' saved [39657]

  File "pythonScript.py", line 4
    <!DOCTYPE html>
    ^
SyntaxError: invalid syntax
Build step 'Execute shell' marked build as failure
[BFA] Scanning build for known causes...
[BFA] No failure causes found
[BFA] Done. 0s
Finished: FAILURE

I figure it has something to do with wget pulling the HTML headers as well, but I haven't been able to figure out a way to strip them. Any help is appreciated.

我认为这也与 wget 拉取 HTML 标头有关,但我一直无法找到剥离它们的方法。任何帮助表示赞赏。

回答by user2357112 supports Monica

You're not downloading the script. You're downloading a GitHub web page with the script and a whole bunch of other stuff on it, like GitHub navigation and a search bar and clickable line numbers.

您没有下载脚本。您正在下载一个 GitHub 网页,其中包含脚本和一大堆其他内容,例如 GitHub 导航、搜索栏和可点击的行号。

Go to that page in your web browser, and you should see a "Raw" link. Click on that, and the resulting page is what you should be wgetting.

在您的网络浏览器中转到该页面,您应该会看到一个“原始”链接。点击它,结果页面就是你应该看到的wget