V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
kaiger
V2EX  ›  Python

关于 Scrapy 请求的 header 自动转换为 bytes 导致请求失败的问题。

  •  
  •   kaiger · 2022-08-29 10:21:37 +08:00 · 1281 次点击
    这是一个创建于 577 天前的主题,其中的信息可能已经有所发展或是发生改变。

    为什么 scrapy 请求的 header 会转换为 bytes 类型,这很难受。

    同一个 header , 用 requests 模块请求就能请求成功,用 scrapy 就失败。

    有什么办法能避免这种情况吗?

    第 1 条附言  ·  2022-08-29 14:54:31 +08:00
    抱歉抱歉,请求失败不是 bytes header 的锅,另有原因。

    header 转换为 bytes 在请求的时候好像被转换回来了,并没有影响。
    xiaoqiao24
        1
    xiaoqiao24  
       2022-08-29 11:34:21 +08:00   ❤️ 1
    2 条路
    1.middleware 里面处理
    2.改底层
    Nostalgia
        2
    Nostalgia  
       2022-08-29 11:53:40 +08:00 via iPhone
    从来没意识到有这个问题……应该是对我爬的网站没啥影响。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1000 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 19:49 · PVG 03:49 · LAX 12:49 · JFK 15:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.