当然,需要在局域网内部。
2、成功监听获取数据后又遇到问题了,令人头大的python编码问题,获取的数据时json对象,
需要解码,查到需要decode('utf-8')把bytes转换为str,但是,json.load(data)还是错误,折腾半天才发现,
我json.load()的对象 是 data = {...}, 看起来真的没问题啊,问题就是监听到的数据 就有 ‘’data =‘’,就是这几个英文,我json.load()半天一个劲报错,气炸了。
3、当我发现了 那个 ''data = '问题后 好办啊 data_str = data[5:] 切片 去掉,终于可以load转换成dict了,但是问题又来了,
此时没接收几次数据,就报错,解码错误,大致是不能用utf-8解码(有中文的原因吧),但是改成各种编码,都没有用,最后,在网上看到了救命的东西,解码时候加上'ignore' 即 data.decode('utf-8','ignore')终于可以接收多一些数据不报错了,我以为这就ok了。
4、没想到,还有一个问题在等着我,接收数据一段时间,然后报给我,说解码不能终止的异常,网上查了,各种说法都有,
有说因为json里面有特殊符号的,有说服务器传来的数据里面有异常信息的...
最后我是从淘宝得到正确答案的,没错,就是万能的淘宝,卖家提示我,可以打印异常调试信息,于是乎,我照做了,发现异常的数据真的没法截止,
正确数据
data_right = {'id': '00272dd0', 'mmac': '2e:3a:e8:27:2d:d0', 'rate': '1', 'wssid': 'TianWei', 'wmac': 'c0:ee:fb:d8:d0:b6', 'time': 'Tue May 01 16:42:30 2018', 'data': [{'mac': 'c0:ee:fb:d8:d0:b6', 'rssi': '-61', 'range': '7.1', 'router': 'TianWei'}, {'mac': 'dc:fe:18:d0:b1:8e', 'rssi': '-70', 'rssi1': '-70', 'range': '15.3', 'router': '002'}, {'mac': '00:11:7f:11:f4:49', 'rssi': '-90', 'range': '84.0', 'router': 'iU-QiFangYuan'}, {'mac': 'c4:36:55:89:76:55', 'rssi': '-82', 'range': '42.5'}, {'mac': '34:96:72:1f:10:c5', 'rssi': '-82', 'rssi1': '-82', 'rssi2': '-81', 'rssi3': '-81', 'range': '39.0'}, {'mac': '34:96:72:f6:50:62', 'rssi': '-86', 'range': '59.7'}, {'mac': '1c:fa:68:30:ea:a2', 'rssi': '-73', 'range': '19.7', 'router': 'nihao'}, {'mac': 'c4:36:55:47:01:9d', 'rssi': '-91', 'range': '91.5'}, {'mac': 'bc:46:99:62:13:b6', 'rssi': '-82', 'range': '42.5', 'router': 'sun1'}, {'mac': 'bc:46:99:e3:5f:ca', 'rssi': '-89', 'range': '77.1', 'router': 'TP-LINK_5FCA'}, {'mac': '50:fa:84:26:f9:3e', 'rssi': '-92', 'range': '99.7', 'router': 'HYRJZ5'}, {'mac': 'fc:d7:33:a3:8b:9c', 'rssi': '-91', 'range': '91.5', 'router': 'TP-LINK_8B9C'}, {'mac': 'd8:32:14:49:a7:10', 'rssi': '-82', 'range': '42.5', 'router': 'Tenda_49A710'}
错误数据:
data_b = b'data={"id":"00272dd0","mmac":"2e:3a:e8:27:2d:d0","rate":"1","wssid":"TianWei","wmac":"c0:ee:fb:d8:d0:b6","time":"Tue May 01 16:16:16 2018","data":[{"mac":"cc:81:da:ce:e2:d0","rssi":"-76","rssi1":"-76","rssi2":"-73","rssi3":"-78","range":"18.1","router":"2.4G"},{"mac":"c8:3a:35:f0:c4:d0","rssi":"-53","rssi1":"-52","rssi2":"-85","rssi3":"-54","range":"4.2","router":"Tenda_F0C4D0"},{"mac":"2c:57:31:6b:38:aa","rssi":"-81","rssi1":"-81","rssi2":"-81","rssi3":"-84","range":"35.8","ts":"2.4G","tmc":"cc:81:da:ce:e2:d0","tc":"Y","ds":"Y"},{"mac":"dc:fe:18:d0:b1:8e","rssi":"-73","rssi1":"-71","rssi2":"-72","rssi3":"-74","range":"16.6","router":"002"},{"mac":"c0:ee:fb:d8:d0:b6","rssi":"-47","rssi1":"-46","rssi2":"-48","rssi3":"-48","range":"2.5","router":"TianWei"},{"mac":"50:0f:f5:8c:ad:f8","rssi":"-84","rssi1":"-83","rssi2":"-88","rssi3":"-89","range":"59.7","router":"Tenda_8CADF8"},{"mac":"00:11:7f:11:f4:49","rssi":"-83","range":"46.3","router":"iU-QiFangYuan"},{"mac":"fc:7c:02:36:69:33","rssi":"-81","rssi1":"-81","rssi2":"-84","rssi3":"-86","range":"59.7","router":"@PHICOMM_31"},{"mac":"c8:3a:35:ab:07:58","rssi":"-85","range":"54.8","router":"Tenda_AB0758"},{"mac":"c4:36:55:89:76:55","rssi":"-78","rssi1":"-80","rssi2":"-82","rssi3":"-81","range":"32.9","router":"360WiFi-897655"},{"mac":"00:1c:a3:05:bf:32","rssi":"-92","rssi1":"-91","range":"91.5"},{"mac":"b0:df:c1:4c:f6:d8","rssi":"-92","rssi1":"-92","rssi2":"-92","rssi3":"-93","range":"91.5"},{"mac":"1c:fa:68:30:ea:a2","rssi":"-70","rssi1":"-70","rssi2":"-68","rssi3":"-69","range":"14.0"},{"mac":"bc:46:99:62:13:b6","rssi":"-90","rssi1":"-89","rssi2":"-88","range":"70.8"},{"mac":"bc:46:99:e3:5f:ca","rssi":"-90","rssi1":"-92","range":"99.7","router":"TP-LINK_5FCA"},{"mac":"78:58:60:48:21:d0","rssi":"-74","rssi1":"-75","rssi2":"-77","range":"27.7","router":"CMCC-yS49"},{"mac":"c8:3a:35:59:0e:60","rssi":"-91","rssi1":"-91","rssi2":"-88","rssi3":"-89","range":"77.1"},{"mac":"34:96:72:1f:10:c5","rssi":"-80","rssi1":"-81","rssi2":"-79","rssi3":"-80","range":"30.2","router":"TP-002"},{"mac":"fc:d7:33:a3:8b:9c","rssi":"-89","range":"77.1","router":"TP-LINK_8B9C"},{"mac":"c8:3a:35:3e:59:10","rssi":"-79","rssi1":"-90","rssi2":"-91","range":"91.5","router":"Tenda_3E5910"},{"mac":"58:d9:d5:1a:9d:e0","rssi":"-91","range":"91.5","router":"Tenda_1A9DE0"},{"mac":"d8:32:14:49:a7:10","rssi":"-75","range":"23.4","router":"Tenda_49A710"},{"mac":"b0:95:8e:0b:33:94","rssi":"-88","rssi1":"-88","range":"70.8"},{"mac":"34:96:72:f6:50:62","rssi":"-79","rssi1":"-81","rssi2":"-82","range":"42.5"},{"mac":"58:d9:d5:ac:02:e8","rssi":"-82","rssi1":"-80","range":"35.8","router":"Tenda_AC02E8"},{"mac":"8c:a6:df:a4:a3:2b","rssi":"-88","rssi1":"-90","range":"84.0"},{"mac":"00:1c:a'