通常我通过 SSH 连接到我的 EC2 实例并运行:
source MYVENV/bin/activate
如何设置我的 cronjob 以激活虚拟环境?我的 Django 脚本需要存储在 ~/.bash_profile 中的环境变量
我尝试按照此处的步骤操作无济于事
SHELL=/bin/bash
*/1 * * * * root source /home/ec2-user/MYVENV/activate && python /home/script.py
Run Code Online (Sandbox Code Playgroud)
这是我上面的当前设置。
我在日志中收到以下错误:
/bin/bash: root: 找不到命令
我是 pytest 的新手,我正在运行一个非常简单的测试来断言模型创建,但运行测试似乎需要大量时间。我大概有 10 件款式的上衣,没有一件是极其复杂的。
4.67 setup
0.69s call
0.09s teardown
Run Code Online (Sandbox Code Playgroud)
这是添加参数的情况(没有参数则超过 30 秒!):
pytest --nomigrations --reuse-db
Run Code Online (Sandbox Code Playgroud)
难道我做错了什么?如何减少这个设置时间?设置时间是否取决于模型数量或其他因素?我无法想象一旦应用程序变大,这将需要多长时间。欢迎任何建议。
我想在 Django 中运行测试,但为了运行测试,我需要访问生产数据库中的数据(我不想设置全新的数据库进行测试)。
如何在不允许脚本中进行写访问的情况下使用生产数据库中的这些数据?我不希望此测试产生任何影响,但我需要访问此数据才能运行此测试。为了获取几行数据而必须启动(并付费)一个全新的数据库似乎很荒谬,有什么建议吗?
我从 python 和curl 得到了不同的响应,尽管它们都使用完全相同的参数。
Python:
import requests
headers = {
'Accept-Language': 'en-US,en',
'Accept': 'text/html,application/xhtml+xml,application/xml',
'Authority': 'www.google.com',
'User-Agent': 'SomeAgent',
'Upgrade-Insecure-Requests': '1',
}
response = requests.get('https://www.avvo.com', headers=headers)
# Returns a 403 response
Run Code Online (Sandbox Code Playgroud)
卷曲:
import shlex, subprocess
cmd = '''curl -H 'Accept-Language: en-US,en' -H 'Accept: text/html,application/xhtml+xml,application/xml' -H 'Authority: www.google.com' -H 'User-Agent: SomeAgent' -H 'Upgrade-Insecure-Requests: 1' https://www.avvo.com'''
args = shlex.split(cmd)
process = subprocess.Popen(args, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
# Returns a 200 response
Run Code Online (Sandbox Code Playgroud)
两个请求均从同一 IP 发送。看起来这是一个 cloudflare 问题,cloudflare 有什么方法可以检测来自 python requests 库的请求与直接的 …
我当前的 nginx 配置如下所示:
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name _;
root /usr/share/nginx/html;
ssl_certificate "PEM";
ssl_certificate_key "PEM";
# It is *strongly* recommended to generate unique DH parameters
# Generate them with: openssl dhparam -out /etc/pki/nginx/dhparams.pem 2048
#ssl_dhparam "/etc/pki/nginx/dhparams.pem";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:SEED:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!RSAPSK:!aDH:!aECDH:!EDH-DSS-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!SRP;
ssl_prefer_server_ciphers on;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass …Run Code Online (Sandbox Code Playgroud) 我有一个对象是字典的字典。我想告诉我的编辑这个对象是这样的,我该怎么做?目前我有:
def do_somthing(dict_of_dicts):
"""
:type dict_of_dicts: dict of dict
"""
for key, value in dict_of_dicts.items():
for key2, value2 in value.items():
print('Key')
Run Code Online (Sandbox Code Playgroud)
但是,我的编辑器(Pycharm)似乎没有注册这个。
python ×6
django ×3
python-3.x ×2
unit-testing ×2
cron ×1
curl ×1
docstring ×1
nginx ×1
pycharm ×1
pytest ×1
virtualenv ×1