[英]How do I run a Python script in Unix
I'm not a Python developer but I need to use this language to set up certain application.我不是 Python 开发人员,但我需要使用这种语言来设置某些应用程序。 I'd like to do basic auth.我想做基本的授权。 Python documentation reads: Python 文档如下:
Making requests with HTTP Basic Auth is very simple:使用 HTTP Basic Auth 发出请求非常简单:
>>> from requests.auth import HTTPBasicAuth
>>> requests.get('https://api.github.com/user', auth=HTTPBasicAuth('user', 'pass')) <Response [200]>
So I created a file where I put:所以我创建了一个文件,我把:
from requests.auth import HTTPBasicAuth
requests.get('https://api.github.com/user', auth=HTTPBasicAuth('user', 'pass'))
However, it is not as simple as the documentation claims.然而,它并不像文档声称的那么简单。 When I run the code I get the following error:当我运行代码时,出现以下错误:
./auth.py: line 1: from: command not found
./auth.py: line 2: syntax error near unexpected token `'https://api.github.com/user','
./auth.py: line 2: `requests.get('https://api.github.com/user', auth=HTTPBasicAuth('user', 'pass'))'
I use Python 2.7.我使用 Python 2.7。
Those are error messages from a bash
script... you probably don't have the correct shebang at the top of your script:这些是来自bash
脚本的错误消息……您的脚本顶部可能没有正确的 shebang:
#!/usr/bin/env python
Then run the script as ./my_script
然后将脚本作为./my_script
运行
Or, use:或者,使用:
python my_script.py
To run the script.运行脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.