V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  binux  ›  全部回复第 264 页 / 共 339 页
回复总数  6773
1 ... 260  261  262  263  264  265  266  267  268  269 ... 339  
2014-05-31 17:38:07 +08:00
回复了 chengxuan 创建的主题 Python 求助 python 报错误 给予解决者 100 元话费
def get_huobi_seller(self):
try:
r = requests.get('http://market.huobi.com/staticmarket/depth_btc_json.js')
return r
except:
time.sleep(18)
self.get_huobi_seller()

你看,except 里面没有 return 啊,`return self.get_huobi_seller()`
虽然不建议,如果一直失败会导致爆栈的
2014-05-31 17:11:48 +08:00
回复了 chengxuan 创建的主题 Python 求助 python 报错误 给予解决者 100 元话费
@chengxuan 我继续猜
请求api封装的时候,为了防止异常,是这么写的

try:
__return requests.post('http://some.api.com/')
except:
__pass

当多次访问之后,requests 出现了
ConnectionError: HTTPConnectionPool(host='some.api.com', port=80): Max retries exceeded with url: /
异常,没有办法 return,于是,函数实际返回空

后面处理没有做判断,亦然调用 ret.json(),于是报错
2014-05-31 15:48:47 +08:00
回复了 chengxuan 创建的主题 Python 求助 python 报错误 给予解决者 100 元话费
让我猜猜,你用的是requests?然后又自己封装了一层,应该返回 response object 的
然后,没有 returen 或者 return 为空了,外面的函数接着调用了 ret.json() 于是失败了?
1 ... 260  261  262  263  264  265  266  267  268  269 ... 339  
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   3157 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 50ms · UTC 11:31 · PVG 19:31 · LAX 03:31 · JFK 06:31
♥ Do have faith in what you're doing.