import re
from ast import literal_eval
e = """betfairlightweight.exceptions.APIError: SportsAPING/v1.0/listMarketBook
Params: {'marketIds': ['1.200293211'], 'priceProjection': {'priceData': ['EX_TRADED'], 'exBestOffersOverrides': {}, 'virtualise': True, 'rolloverStakes': False}}
Exception: None
Error: {'code': -32099, 'message': 'ANGX-0006', 'data': {'APINGException': {'requestUUID': '...........', 'errorCode': 'UNEXPECTED_ERROR', 'errorDetails': ''}, 'exceptionname': 'APINGException'}}
Full Response: {'jsonrpc': '2.0', 'error': {'code': -32099, 'message': 'ANGX-0006', 'data': {'APINGException': {'requestUUID': '..........', 'errorCode': 'UNEXPECTED_ERROR', 'errorDetails': ''}, 'exceptionname': 'APINGException'}}, 'id': 1}"""
data = dict(x.split(':', 1) for x in e.splitlines())
data = {k.strip():literal_eval(v) if '{' in v else v.strip() for k,v in data.items()}
print(data)
输出:
{'betfairlightweight.exceptions.APIError': 'SportsAPING/v1.0/listMarketBook', 'Params': {'marketIds': ['1.200293211'], 'priceProjection': {'priceData': ['EX_TRADED'], 'exBestOffersOverrides': {}, 'virtualise': True, 'rolloverStakes': False}}, 'Exception': 'None', 'Error': {'code': -32099, 'message': 'ANGX-0006', 'data': {'APINGException': {'requestUUID': '...........', 'errorCode': 'UNEXPECTED_ERROR', 'errorDetails': ''}, 'exceptionname': 'APINGException'}}, 'Full Response': {'jsonrpc': '2.0', 'error': {'code': -32099, 'message': 'ANGX-0006', 'data': {'APINGException': {'requestUUID': '..........', 'errorCode': 'UNEXPECTED_ERROR', 'errorDetails': ''}, 'exceptionname': 'APINGException'}}, 'id': 1}}
漂亮的输出:
import json
print(json.dumps(data, indent=3))
...
{
"betfairlightweight.exceptions.APIError": "SportsAPING/v1.0/listMarketBook",
"Params": {
"marketIds": [
"1.200293211"
],
"priceProjection": {
"priceData": [
"EX_TRADED"
],
"exBestOffersOverrides": {},
"virtualise": true,
"rolloverStakes": false
}
},
"Exception": "None",
"Error": {
"code": -32099,
"message": "ANGX-0006",
"data": {
"APINGException": {
"requestUUID": "...........",
"errorCode": "UNEXPECTED_ERROR",
"errorDetails": ""
},
"exceptionname": "APINGException"
}
},
"Full Response": {
"jsonrpc": "2.0",
"error": {
"code": -32099,
"message": "ANGX-0006",
"data": {
"APINGException": {
"requestUUID": "..........",
"errorCode": "UNEXPECTED_ERROR",
"errorDetails": ""
},
"exceptionname": "APINGException"
}
},
"id": 1
}
}