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
onsala
V2EX  ›  Python

网易云音乐 post 请求闪退的原因有哪些?

  •  
  •   onsala · 2017-02-21 15:36:52 +08:00 · 2130 次点击
    这是一个创建于 2613 天前的主题,其中的信息可能已经有所发展或是发生改变。

    使用 requests 模拟网易云音乐的登录,运行下面这段代码,代码会立即闪退,感觉似乎根本没有做 post 请求,请问原因可能是什么,程序退出的速度太快了。

    import requests
    
    
    def login(username, password):
        session = requests.Session()
        url = 'https://music.163.com/weapi/login/'
        headers = {
            'Cookie': 'appver=1.5.2', 'Referer': 'http://music.163.com/', 
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36'
        }
    
        text = {
            'username': username,
            'password': password,
            'rememberLogin': 'true'
        }
        data = encrypted_request(text)
        try:
            r = session.post(url, data=text, headers=headers)
            print r.text
        except requests.exceptions.RequestException as e:
            print e
    
    # 邮箱登录
    login('[email protected]', 'password')
    

    encrpted_requests 的地址 https://gist.github.com/ormsf/130d72fe0c81cbf48e4c357dfe94a4c8

    第 1 条附言  ·  2017-02-21 16:43:58 +08:00

    data = encrypted_request(text)要改成data = encrypted_request(data)。只是这样还是会502错误。

    第 2 条附言  ·  2017-02-21 16:46:20 +08:00
    附言 1 写错了:
    是`r = session.post(url, data=text, headers=headers)`改成`r = session.post(url, data=data, headers=headers)`
    holyzhou
        1
    holyzhou  
       2017-02-21 16:26:49 +08:00   ❤️ 1
    没跑 , 但是你 post 的 data 还是用的没加密的 text 字典 这个有问题吧
    onsala
        2
    onsala  
    OP
       2017-02-21 16:42:50 +08:00
    @holyzhou 找了一个上午,多谢:P 。只是返回的状态码是 502 ,我重新试下。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5031 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 03:48 · PVG 11:48 · LAX 20:48 · JFK 23:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.