2014-09-30 72 views
1

我有一個簡單的觀點如下:Django的視圖recieving不完整的POST有效載荷

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

發帖時映射到該視圖的URL,我的控制檯顯示不完整和破碎的有效載荷。它的大小應該是它的三分之一,即使如此,第三個對我來說也不是連續的,而是以幾個隨機部分交付。就像如下:

2014年9月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年9月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":"[email protected]: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的基礎設施問題,所以它很可能是我的最終目標。但我不知道什麼

+0

你如何發佈?你可以發佈一些你發佈什麼/如何的代碼。 – awwester 2014-09-30 18:57:45

+0

是的,事實上,這是Github webhook POSTs,我已經測試過Github使用以下方式正確發送它們: http://requestb.in/qhgo7nqh?inspect 您可以看到Github發送的有效負載 – user1079404 2014-09-30 19:00:32

回答

1

我想你只是看到一個日誌工件。該消息是作爲單個POST發送的,但記錄器正在分解消息,因爲消息太長。而不僅僅是print消息(將消息發送到服務器日誌),使用print >> sys.stderr, request.body,它將顯示在錯誤日誌中,而不會截斷。

1

我猜你的打印語句會截斷str(request.body)的輸出,這會隱式發生,但POST的實際內容就在那裏。試試這個:

import pprint 

@csrf_exempt 
def stackcommits(request): 
    pprint.pprint(request.body) 
    return HttpResponse("") 
+0

剛剛嘗試過,但似乎仍然這樣做。當我讓Github使用urlencode頭部(與json相同)時,我似乎在打印時始終會在服務器日誌中出現3個獨立的塊。我得到了開始,在中間的某個地方,然後是請求的結尾。但是有很多隨機丟失之間。你能想出任何其他方式來測試我的服務器是否正確接收數據? – user1079404 2014-09-30 19:48:02