我正在尝试为 Falcon 框架编写一些 pytest,并按照此处的说明进行操作。我想模拟一个 POST 请求。但是,我不断收到以下错误
测试/test_app.py:29: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ../../harvester -venv/lib/python2.7/site-packages/falcon/testing/client.py:170:在json中返回json.loads(self.text)/System/Library/Frameworks/Python.framework/Versions/2.7/lib /python2.7/json/ init .py:338:在加载中返回 _default_decoder.decode(s) /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py:366 : 在解码 obj 中,end = self.raw_decode(s, idx=_w(s, 0).end())
自我 = , s = '', idx = 0
def raw_decode(self, s, idx=0): """Decode a JSON document from ``s`` (a ``str`` or ``unicode`` beginning with a JSON document) and return a 2-tuple of the Python representation and the index in ``s`` where the document ended. This can be used to decode a JSON document from a string that may have extraneous data at the end. """ try: obj, end = self.scan_once(s, idx) except StopIteration:
raise ValueError("No JSON object could be decoded") E ValueError: No JSON object could be decoded
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py:384:ValueError
这是我正在尝试编写的 Falcon 测试。当我验证我在JSONlint.comdata
上放入变量的 JSON 时,它向我显示数据是有效的,因此问题似乎与格式无关。
import json
import pytest
from falcon import testing
from harvester.app import api
@pytest.fixture()
def client():
return testing.TestClient(api)
def test_elasticsearch_endpoint(client):
data = {
"Type": "SubscriptionConfirmation",
"MessageId": "0a069ec4-2e6f-4436-9f1d-aa55c3b048f9",
"Token": "2336412f37fb68751e6e241d59b68cb9ca332001818266bdd4984dd60a76ff2c8a43220b28241ad0ae6659d6313bb2336e98d19bdbc52e0c99578ad43934324b5e73a20e9ad517741cf14a57793d052e9986038ee688a059b34e49746d106bcd597f18f7ff3560be204ef8cd339a3c5276bfa3cc784a7904c8720519387a0",
"TopicArn": "arn:aws:sns:ap-south-1:141592612890",
"SubscribeURL": "https://sns.ap-south-1.amazonaws.com/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:ap-south-1:141592612890:harvester_test&Token=2336412f37fb687f5d51e6e241d59b68cb9ca332001818266bdd4984dd60a76ff2c8a41ad0ae6659d6313bb2336e98d19bdbc52e0c99578ad43934324b5e73a20e9ad517741cf14a57793d052e9986038ee688a059b34e49746d106bcd597f18f7ff3560be204ef8cd339a3c5276bfa3cc784a7904c8720519387a0",
"Timestamp": "2017-06-01T13:22:49.849Z",
"SignatureVersion": "1",
"Signature": "Pj9F8PrgqPkSuLjHtrJ9pmh3ZH3kZBaLs5Ywx1C0rrOc4PJp3hYiria9SZr1Xm8uE549khxDFIdAsnGee9fSeO7tZWSNI3W3gRLVnIJ0uAjxU0oicj3P7NnGQ5kUnihKva//Q39RlZOIr4OsxTvOrXnag6M32aC3pEFdBaXJqO0iJJOokT+mmoWa9BWfHXnb/ORAigo50BXsVNSN92PRZAZ7qTeypZSU70EF1+vKNt7mbxrOE2/wpOtb7uDfg/ZW8yZQQqr100bnQVfStDSp6MzID+vupQhM2PR/gS84INA+VdOUhxll/kEkDE98tR9OrNz/PITts5XSg==",
"SigningCertURL": "https://sns.ap-south-1.amazonaws.com/SimpleNotificationService-b95095beb82e8f6a04.pem"
}
result = client.simulate_post('/v1/track/analytics', body=json.dumps(data))
print result.json
任何线索为什么会发生这种情况?