您好我正在尝试使用http://bobrochel.blogspot.com/2010/11/bad-servers-chunked-encoding-and.html修补我的python代码,但是当在代码中的任何位置添加此代码段时,我总是会得到无效的语法。我做错了什么?
我的代码的开头是这样的:
import logging
import argparse
import sys
from arbitrer import Arbitrer
def patch_http_response_read(func):
def inner(*args):
try:
return func(*args)
except httplib.IncompleteRead, e:
return e.partial
return inner
httplib.HTTPResponse.read = patch_http_response_read(httplib.HTTPResponse.read)
class ArbitrerCLI:
def __init__(self):
答案 0 :(得分:1)
正确缩进。
Python 3.x中的import httplib
import logging
import argparse
import sys
from arbitrer import Arbitrer
def patch_http_response_read(func):
def inner(*args):
try:
return func(*args)
except httplib.IncompleteRead as e:
return e.partial
return inner
httplib.HTTPResponse.read = patch_http_response_read(httplib.HTTPResponse.read)
class ArbitrerCLI:
def __init__(self):
...
答案 1 :(得分:1)
except
不再那样了。
except httplib.IncompleteRead as e: