
1 huyiwei May 31, 2014 汗~明显变量没有赋值 |
2 phyng May 31, 2014 楼主赶紧贴代码。。。 |
3 anheiyouxia May 31, 2014 via Android 虽然我没学过Python,但是这个错误不是很明显吗?要么你没初始化,要么在传这个东西的时候就把这个产量搞丢了了 正确做法应该是直接看代码,看所有这个产量经过哪些操作,再看不懂,调试总可以了吧(如果你的IDE有调试功能的话)或者直接在所有用到这个产量的方法打印一下这个东西啊 |
4 Crossin May 31, 2014 XXX.json XXX为None |
5 manfay May 31, 2014 import json |
6 xiandao7997 May 31, 2014 via Android 4楼对的,空对象找不到属性 |
7 xiaowangge May 31, 2014 via iPad import json |
8 binux May 31, 2014 让我猜猜,你用的是requests?然后又自己封装了一层,应该返回 response object 的 然后,没有 returen 或者 return 为空了,外面的函数接着调用了 ret.json() 于是失败了? |
9 RIcter May 31, 2014 via iPad ...这段错误要是有人能知道为什么报错..我给充话费.. |
12 funagi May 31, 2014 >>> None.json Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'json' |
13 chengxuan OP |
14 skydiver May 31, 2014 @anheiyouxia 这么多产量。。。 |
15 liushuaikobe May 31, 2014 |
16 est May 31, 2014 NullReferenceException NullPointerException |
17 binux May 31, 2014 @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(),于是报错 |
18 anheiyouxia May 31, 2014 via Android @skydiver 手机打字,九宫格拼音,产量和变量呃于是242654264,不要太在意这些细节≥≤ |
19 chengxuan OP @liushuaikobe @binux @Crossin 源码贴出,跪谢各位大神。 #coding=utf-8 import time, re, requests, md5, urllib, urllib2, json ,sys ,os #sys.path.append(os.path.dirname(__file__).replace('\\','/')) from huobi import HuoBi from bitfinex import Bitfinex from configs import config,keys class getprice(object): def __init__(self): #获取动态配置 self.huobi = HuoBi(keys['huobi']['key'],keys['huobi']['secretKey']) self.bitf = Bitfinex(keys['bitf']['key'],keys['bitf']['secretKey']) def buy_seller(self): p1 = self.get_huobi() pr1 = p1['sell'] p2 = self.get_bitf() pr2 = p2['sell'] * config['rate'] if pr1 > pr2: pre = (pr1 - pr2) / pr1 * 100 if pre >= config['agio']: self.huobi_sell(p1['buy']) self.bitf_sell('buy',p2['sell']) else: pre = (pr2 - pr1) / pr2 * 100 if pre >= config['agio']: self.huobi_buy(p1['sell']) self.bitf_sell('sell',p2['buy']) print("huobi : %s %s finex : %s ") % (pr1,pre,pr2) 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() def get_bitf_seller(self): try: r = requests.get('https://api.bitfinex.com/v1/book/btcusd') return r except: time.sleep(18) self.get_bitf_seller() def get_huobi(self): r1 = self.get_huobi_seller() t =r1.json() p1 = t['asks'][-5] p2 = t['bids'][4] pr1 = float(p1[0]) pr2 = float(p2[0]) return {'buy':pr2,'sell':pr1} def get_bitf(self): r2 = self.get_bitf_seller() t = r2.json() p1 = t['asks'][4] p2 = t['bids'][4] pr1 = float(p1['price']) pr2 = float(p2['price']) return {'buy':pr2,'sell':pr1} def huobi_sell(self,price=''): #getattr(huobi,method) price = self.get_huobi() price = price['buy'] info = self.huobi.sell(price,config['amount']) #{u'result': u'success', u'id': 18161354} print(info) def huobi_buy(self,price): info = self.huobi.buy(price,config['amount']) print(info) def bitf_sell(self,side='sell',price=''): """ symbol (string): The name of the symbol (see `/symbols`). amount (decimal): Order size: how much to buy or sell. price (price): Price to buy or sell at. May omit if a market order. exchange (string): "bitfinex". side (string): Either "buy" or "sell". type (string): Either "market" / "limit" / "stop" / "trailing-stop" / "fill-or-kill" / "exchange market" / "exchange limit" / "exchange stop" / "exchange trailing-stop" / "exchange fill-or-kill". (type starting by "exchange " are exchange orders, others are margin trading orders) is_hidden (bool) true if the order should be hidden. Default is false. """ price = self.get_bitf() price = price['buy'] params = { "symbol":"btcusd", "amount" : str(config['amount']), "price" : str(price), "exchange" : "bitfinex", "side" : side, "type" : "exchange market", } info = self.bitf.order_new(params) print(info) x = getprice() while config['start']: x.buy_seller() time.sleep(18) |
20 smallghost May 31, 2014 这100元话费还是有作用的,我是打酱油的 |
21 binux May 31, 2014 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()` 虽然不建议,如果一直失败会导致爆栈的 |
22 chengxuan OP @binux qq或者mail发给我[email protected] |
23 konakona May 31, 2014 =..= 来晚了啊!!!这么简单的东西虽然我是个phper也能解决啊!!!100块啊!!! |
26 YouXia May 31, 2014 |
28 lightening May 31, 2014 @binux 真厉害,猜都能猜对。代码缩进丢了还能读…… |
29 lsongdev May 31, 2014 via iPhone 我又想吐槽 Python 的代码缩进语法了 。 |
30 d0o0g May 31, 2014 哈哈,错误很明显,大家很踊跃,我是看这100块钱进来的 |
36 xuzhe Jun 1, 2014 这一百块引出个大神,值了。 |