首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Grooveshark早期关闭连接(httplib.BadStatusLine)

Grooveshark早期关闭连接(httplib.BadStatusLine)
EN

Stack Overflow用户
提问于 2012-06-15 23:06:52
回答 1查看 1K关注 0票数 1

我想和grooveshark取得联系。因为这条蟒蛇是我的首选语言。但我撞到了砖墙。看起来grooveshark最近改变了他们协议的一部分,或者我可能遇到了python的限制。

我正在与来自github的JackTheRipper51“合作”,他为grooveshark创建了这个库:https://github.com/jacktheripper51/groove-dl --它实际上不是一个库,但我很快将它重新编码为一个库。

本周早些时候,它运行良好,我能够在我的项目中使用它。但是两天前,getToken函数出现故障,httplib开始返回httplib.BadStatusLine: '',这意味着服务器提前关闭了连接。

从这项研究中,我开始研究grooveshark的javascript和flash源代码,但没有返回任何有价值的内容。所以我做了任何一个精神正常的人花了5个小时看反编译actionscript,而之前还没有在这些内容中编码一行的人会做的事情,并将其归咎于groovesharks服务器。

具体来说,我认为grooveshark可能会拒绝使用Connection: close头的连接。因此,我决定在Chrome的REST Console扩展中测试它。

我让python脚本转储它正在编码的json,然后将它粘贴到Rest控制台中,点击POST,然后它就返回了所需的数据。我现在确信我是对的,这不是不可能的。

我的下一步是用httplib2 (因为它支持Connection: keep-alive)编写代码,但问题仍然存在。

我在wireshark中进行了测试(删除https中的SSL,它确实发送Connection: keep-alive,这会导致grooveshark响应,但使用https required)。

我只修改了代码的一小部分。

完全改变的getToken()

代码语言:javascript
复制
def getToken():
    global staticHeader, _token
    post = {}
    post["parameters"] = {}
    post["parameters"]["secretKey"] = hashlib.md5(staticHeader["session"]).hexdigest()
    post["method"] = "getCommunicationToken"
    post["header"] = staticHeader
    post["header"]["client"] = "htmlshark"
    post["header"]["clientRevision"] = "20120312"
    header = {"User-Agent": _useragent, "Referer": _referer, "Content-Type":"application/json", "Cookie":"PHPSESSID=" + staticHeader["session"], "Connection":"keep-alive"}
    response, content = http.request("https://grooveshark.com/more.php?getCommunicationToken", "POST" ,body = json.JSONEncoder().encode(post), headers = header)
    print response
    #_token = json.JSONDecoder().decode(gzip.GzipFile(fileobj=(StringIO.StringIO(conn.getresponse().read()))).read())["result"]
    #print _token

我添加了httplib2初始化的内容:

代码语言:javascript
复制
http = httplib2.Http()

我导入了httplib2:

代码语言:javascript
复制
import httplib, httplib2

我还重命名了json构造函数,仅仅是因为我想要更多描述性。

完整的回溯是:

代码语言:javascript
复制
Traceback (most recent call last):
  File "C:\Users\Delusional Logic\Documents\GitHub\groove-dl\python\groove.py", line 141, in <module>
    getToken()
  File "C:\Users\Delusional Logic\Documents\GitHub\groove-dl\python\groove.py", line 51, in getToken
    response, content = http.request("https://grooveshark.com/more.php?getCommunicationToken", "POST" ,body = json.JSONEncoder().encode(post), headers = header)
  File "C:\Python27\lib\site-packages\httplib2-0.7.4-py2.7.egg\httplib2\__init__.py", line 1544, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "C:\Python27\lib\site-packages\httplib2-0.7.4-py2.7.egg\httplib2\__init__.py", line 1294, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "C:\Python27\lib\site-packages\httplib2-0.7.4-py2.7.egg\httplib2\__init__.py", line 1264, in _conn_request
    response = conn.getresponse()
  File "C:\Python27\lib\httplib.py", line 1027, in getresponse
    response.begin()
  File "C:\Python27\lib\httplib.py", line 407, in begin
    version, status, reason = self._read_status()
  File "C:\Python27\lib\httplib.py", line 371, in _read_status
    raise BadStatusLine(line)
httplib.BadStatusLine: ''

是什么导致了BadStatusLine,以及如何修复它。

我知道他们在开会前一天开了8个小时的会,我敢打赌这是议程上的事。

更新: JackTheRipper51告诉我,无论您发送什么,对grooveshark.com/ me . you的所有ssl请求都会发生这种情况。这让我相信这是蟒蛇在捉弄我们。

更新2:

JackTheRipper51刚刚告诉我,它确实是python。这是他的帖子:

,我根本不需要C。准备被激怒。一个简单的

代码语言:javascript
复制
curl -H "Content-Type: text/plain" -d "@jsontest" "https://grooveshark.com/more.php?getCommunicationToken" -v on a linux

盒给我买了个记号..。jsontest这里

代码语言:javascript
复制
{"header":{"client":"mobileshark","clientRevision":"20120227","privacy":0,"country":{"ID":63,"CC1":4611686018427388000,"CC2":0,"CC3":0,"CC4":0,"DMA":0,"IPR":0},"uuid":"BF5D03EE-91BB-40C9-BE7B-11FD43CAF0F0","session":"1d9989644c5eba85958d675b421fb0ac"},"method":"getCommunicationToken","parameters":{"secretKey":"230147db390cf31fc3b8008e85f8a7f1"}}

--即使json在语法上不正确,它也总是至少返回一些标题!一直以来都是Python。

剩下的唯一问题是为什么python要这么做?

EN

回答 1

Stack Overflow用户

发布于 2012-06-16 10:34:53

这个问题已经“解决了”,或者已经找到了原因。

JackTheRipper向python提交了错误,在那里他们确认导致超时连接的确实是ssl问题,更确切地说是OpenSSL0.9.8。

Bug报告:http://bugs.python.org/issue15082

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11059229

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档