小编And*_*ane的帖子

为什么要在python请求中使用iter_content和chunk_size

我为什么要使用iter_content,特别是我对使用chunk_size的用途感到非常困惑,因为我尝试过使用它,并且在下载成功后似乎以各种方式保存了文件。

g = requests.get(url, stream=True)

with open('c:/users/andriken/desktop/tiger.jpg', 'wb') as sav:
    for chunk in g.iter_content(chunk_size=1000000):
        print (chunk)
        sav.write(chunk)
Run Code Online (Sandbox Code Playgroud)

帮助我了解的用法,iter_content当您看到将1000000字节用作时chunk_size,会发生什么,确切的目的和结果是什么?

python chunks python-requests

4
推荐指数
2
解决办法
1万
查看次数

为 CustomUser 指定的未知字段(密码 1、密码 2)

Internal Server Error: /admin/account/customuser/add/
Traceback (most recent call last):
  File "C:\Users\Andriken\Documents\Prac\djangoexample\bookmarks\mysite_env\lib\site-packages\django\contrib\admin\options.py", line 642, in get_form
    return modelform_factory(self.model, **defaults)
  File "C:\Users\Andriken\Documents\Prac\djangoexample\bookmarks\mysite_env\lib\site-packages\django\forms\models.py", line 543, in modelform_factory
    return type(form)(class_name, (form,), form_class_attrs)
  File "C:\Users\Andriken\Documents\Prac\djangoexample\bookmarks\mysite_env\lib\site-packages\django\forms\models.py", line 252, in __new__
    raise FieldError(message)
django.core.exceptions.FieldError: Unknown field(s) (password2, password1) specified for CustomUser

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Andriken\Documents\Prac\djangoexample\bookmarks\mysite_env\lib\site-packages\django\core\handlers\exception.py", line 39, in inner
    response = get_response(request)
  File "C:\Users\Andriken\Documents\Prac\djangoexample\bookmarks\mysite_env\lib\site-packages\django\core\handlers\base.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "C:\Users\Andriken\Documents\Prac\djangoexample\bookmarks\mysite_env\lib\site-packages\django\core\handlers\base.py", line 187, …
Run Code Online (Sandbox Code Playgroud)

python django django-admin

4
推荐指数
1
解决办法
4361
查看次数

标签 统计

python ×2

chunks ×1

django ×1

django-admin ×1

python-requests ×1