1

我有一个简单的看法如下:

@csrf_exempt
def stackcommits(request):
    print request.body
    return HttpResponse("")

当我 POST 到映射到此视图的 URL 时,我的控制台显示了一个不完整且损坏的有效负载。它大约是它应有的尺寸的三分之一,即使如此,对我来说第三个也不是连续的,而是随机交付的。如下:

2014-09-30 18:47:21
<QueryDict: {u'payload': [u'{"zen":"Avoid administrative distraction.","hook_id":3103635,"hook":{"url":"https://api.github.com/repos/valeyard/SearchDemon/hooks/3103635","test_url":"https://api.github.com/repos/valeyard/SearchDemon/hooks/3103635/test","id":3103635,"name":"web","active":true,"events":["push"],"config":{"secret":"","url":"http://searchdemon.pythonanywhere.com/searchdemon/stackcommits/","content_type":"json","insecure_ssl":"0"},"last_response":{"code":null,"status":"unused","message":null},"updated_at":"2014-09-29T20:56:33Z","created_at":"2014-09-29T20:56:33Z"},"repository":{"id":24075885,"name":"SearchDemon","full_name":"valeyard/SearchDemon","owner":{"login":"valeyard","id":5278331,"avatar_url":"https://avatars.githubusercontent.com/u/5278331?v=2","gravatar_id":"","url":"https://api.github.com/users/valeyard","html_url":"https://github.com/valeyard","followers_url":"https://api.github.com/users/valeyard/followers",

2014-09-30 18:47:21
.github.com/repos/valeyard/SearchDemon/issues{/number}","pulls_url":"https://api.github.com/repos/valeyard/SearchDemon/pulls{/number}","milestones_url":"https://api.github.com/repos/valeyard/SearchDemon/milestones{/number}","notifications_url":"https://api.github.com/repos/valeyard/SearchDemon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/valeyard/SearchDemon/labels{/name}","releases_url":"https://api.github.com/repos/valeyard/SearchDemon/releases{/id}","created_at":"2014-09-15T22:10:54Z","updated_at":"2014-09-24T17:12:44Z","pushed_at":"2014-09-29T20:42:34Z","git_url":"git://github.com/valeyard/SearchDemon.git","ssh_url":"git@github.com:valeyard/SearchDemon.git","clone_url":"https://github.com/valeyard/SearchDemon.git","svn_url":"https://github.com/valeyard/SearchDemon","homepage":null,"size":1172,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":tr

有任何想法吗?有人告诉我,这不是 PA 的基础设施问题,所以很可能是我的问题。但我不知道是什么

4

2 回答 2

1

我认为您只是看到了一个日志记录工件。消息作为单个 POST 传递,但记录器正在分解消息,因为它太长了。而不是只printing 消息(将其发送到服务器日志),使用print >> sys.stderr, request.body它将出现在错误日志中而不会被截断。

于 2014-10-01T09:50:47.487 回答
1

我猜你的 print 语句正在截断隐式发生的 str(request.body) 的输出,但 POST 的实际内容就在那里。尝试这个:

import pprint

@csrf_exempt
def stackcommits(request):
    pprint.pprint(request.body)
    return HttpResponse("")
于 2014-09-30T19:25:57.197 回答