当我在brew安装版本的python 2.7上使用pip冻结时,我得到一个导入错误没有名为zlib的模块.
? ~ pip freeze
Traceback (most recent call last):
File "/usr/local/bin/pip", line 9, in <module>
load_entry_point('pip==7.1.2', 'console_scripts', 'pip')()
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 558, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2682, in load_entry_point
return ep.load()
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2355, in load
return self.resolve()
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2361, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/local/lib/python2.7/site-packages/pip/__init__.py", line 15, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/local/lib/python2.7/site-packages/pip/vcs/mercurial.py", line 10, in <module>
from pip.download import …Run Code Online (Sandbox Code Playgroud) 我最近从python 3.5升级到python 3.6(在macOS上使用brew).然而virtualenvwrapper现在似乎被打破了,我得到了错误.不幸的是,重新安装没有帮助.
mkvirtualenv:78: /usr/local/bin/virtualenv: bad interpreter: /usr/local/opt/python3/bin/python3.5: no such file or directory
Run Code Online (Sandbox Code Playgroud)
我已VIRTUALENV_PYTHON=python3设置,所以默认是使用python3安装virtualenv.
我正在尝试为 django allauth 编写一个登录测试,但是尽管该应用程序工作正常并且我可以登录,但当我编写登录测试时,它无法正确登录,并且由于验证错误“ Response didn't redirect as expected: Response code was 200 (expected 302)
302 != 200e-”而出现断言错误您指定的邮件地址和/或密码不正确'
(目前 test_login 失败,但其他两个测试通过)
在这里查看 django all-auth 中的测试: https: //github.com/pennersr/django-allauth/blob/master/allauth/account/tests.py 我可以看到他们在测试登录时还创建了一个 EmailAddress 对象 -我不确定为什么或者是否需要这样做?
class TestLoginView(TestCase):
def setUp(self):
self.client = Client()
self.username = "test@test.com"
self.password = "password"
user = get_user_model().objects.create_user(self.username, self.password)
# EmailAddress.objects.create(user=user, email=self.username, primary=True, verified=True)
def test_login(self):
response = self.client.post(reverse(
settings.LOGIN_URL), {"login": self.username, "password": self.password}
)
self.assertRedirects(response, settings.LOGIN_REDIRECT_URL, fetch_redirect_response=False)
def test_wrong_login(self):
response = self.client.post(reverse(
settings.LOGIN_URL), {"login": "bad@login.com", "password": "wrong"}
)
validation_error …Run Code Online (Sandbox Code Playgroud) 我正在尝试习惯迭代器.为什么我输入
b = list(reversed([1,2,3,4,5]))
Run Code Online (Sandbox Code Playgroud)
它会给我一个反向列表,但是
c = str(reversed('abcde'))
Run Code Online (Sandbox Code Playgroud)
不会给我一个反转的字符串?
在网络选项卡 - >按 XHR 请求过滤时,当我使用“复制为curl”复制HTTP请求时。它似乎没有复制 HTTP 方法。然而,在测试外部 api 时,这似乎不会造成问题。(按照 chrome 中指定的 GET 和 POST 请求进行验证)。我对curl不太熟悉,但是其他人在复制时是否也看到同样缺乏HTTP方法?
例如:
$ curl 'https://api.somedomain.com' -H 'origin: https://www.somedomain.com' -H 'accept-encoding: gzip, deflate' -H 'accept-language: en-GB,en-US;q=0.8,en;q=0.6' -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36' -H 'content-type: application/json' -H 'accept: */*' -H 'referer: https://www.somedomain.com/path/path2' -H 'authority: api.theenergyshop.co.uk' --data-binary '{'somepayload: 'test'}' --compressed
Run Code Online (Sandbox Code Playgroud) 我最近将日期字段更改为整数字段(数据以剩余月数而不是日期指定)。
然而,尽管当我尝试迁移时 make migrations 命令工作正常,但由于类型转换错误而失败(注意使用 postgres 9.5)。请注意,模型只有 1 个实例/条目,我现在也已将其删除,并且由于某种原因迁移仍然失败?
File "/Users/Yunti/.virtualenvs/switcher5/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: cannot cast type date to integer
LINE 1: ...end_date_fixed" TYPE integer USING "end_date_fixed"::integer
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/Yunti/.virtualenvs/switcher5/lib/python3.5/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/Users/Yunti/.virtualenvs/switcher5/lib/python3.5/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/Yunti/.virtualenvs/switcher5/lib/python3.5/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/Yunti/.virtualenvs/switcher5/lib/python3.5/site-packages/django/core/management/base.py", …Run Code Online (Sandbox Code Playgroud) 我一直试图调试为什么我的几个模型中的last_updated字段没有被更新时model.objects.filter(**lookups).update(**defaults),例如:
class PaymentMethod(models.Model):
MONTHLY_DIRECT_DEBIT = 'MDD'
QUARTERLY_DIRECT_DEBIT = 'QDD'
CASH_OR_CHEQUE = 'CAC'
PAY_IN_ADVANCE = 'PYM'
PAYMENT_CHOICES = (
(MONTHLY_DIRECT_DEBIT, 'Monthly Direct Debit'),
(QUARTERLY_DIRECT_DEBIT, 'Quarterly Direct Debit'),
(CASH_OR_CHEQUE, 'Cash or Cheque'),
(PAY_IN_ADVANCE, 'Pay Monthly in Advance'),
)
unique_id = models.CharField(max_length=3, choices=PAYMENT_CHOICES)
last_updated = models.DateTimeField(auto_now=True)
def __str__(self):
Run Code Online (Sandbox Code Playgroud)
在这里,我只是尝试更新单个条目,而不需要将实例加载到内存中.这似乎是一个无法解决的问题,在docshttps://code.djangoproject.com/ticket/15566中解释了'bug'(出于某种原因,我无法在文档中看到它).
但是,更新单行的最佳方法是什么,包括last_updated字段(无需加载到内存中)?
我收到错误:“‘await’操作数的类型必须是有效的 Promise,或者不得包含可调用的‘then’成员。” 当使用基于 Promise .then() 的语法更改测试格式时,该语法适用于使用 async/await。这是我下面的尝试。
it('downloads successfully', async () => {
cy.get(downloadButton).click();
const csv = await cy.readFile(filename, { timeout: 15000 });
csv.should('have.length.gt', 20);
expect(csv, 'number of records').to.have.length(10);
})
Run Code Online (Sandbox Code Playgroud)
前
cy.readFile(filename, { timeout: 15000 })
.should('have.length.gt', 20)
.then(validateCsv);
Run Code Online (Sandbox Code Playgroud) 我想在booleanfield上选择是/否.默认小部件是checkboxinput.但是,如果我使用Select I覆盖默认小部件,则获得:
NameError: Select is not defined
我想这可能是因为我需要设置Yes/No来关联booleanfield中的布尔值,但不确定应该如何做?
模型:
class User(models.Model):
online_account = models.BooleanField()
Run Code Online (Sandbox Code Playgroud)
形成:
class AccountForm(forms.ModelForm):
class Meta:
model = User
fields = ('online_account')
labels = {
'online_account': 'Do you have an online account',
}
widgets = {'online_account': Select()}
Run Code Online (Sandbox Code Playgroud) 我目前正在尝试从 tar 文件中的 pg_dump (大约 100mb)创建的备份中恢复数据库。
但是尝试恢复
pg_restore -U postgres -f "example.tar"
只是一直挂着,似乎从来没有工作过。
尝试诊断和解决问题的最佳方法是什么?
python ×5
django ×3
postgresql ×2
async-await ×1
curl ×1
django-forms ×1
homebrew ×1
iterator ×1
javascript ×1
linux ×1
list ×1
pip ×1
string ×1