我試圖讓投票API能夠正常工作,但是我得到錯誤.error.USER_REQUIRED。想不通爲什麼,但我認爲我必須被髮送modhash或會話cookie錯誤的方式,如登錄進入低谷精細Reddit API和投票。不接受modhash/cookie。 .error.USER_REQUIRED
我的代碼看起來是這樣的:
UP = {'user': username, 'passwd': password, 'api_type': 'json',}
client = requests.session()
r = client.post('http://www.reddit.com/api/login', data=UP)
j = json.loads(r.text)
mymodhash = j['json']['data']['modhash']
url = 'http://www.reddit.com/api/vote/.json'
postdata = {'id': thing, 'dir': newdir, 'uh': mymodhash}
vote = client.post(url, data=json.dumps(newdata))
錯誤:
{"jquery": [[0, 1, "refresh", []], [0, 2, "attr", "find"], [2, 3, "call", [".error.USER_REQUIRED"]], [3, 4, "attr", "show"], [4, 5, "call", []], [5, 6, "attr", "text"], [6, 7, "call", ["please login to do that"]], [7, 8, "attr", "end"], [8, 9, "call", []]]}
什麼是'用戶代理':'請求測試'? –
這表明你是一個標識爲'Requests test'的客戶。根據Reddit的API,這個用戶代理應該更具描述性:https://github.com/reddit/reddit/wiki/API#rules。另外值得注意的是,Reddit的API不再正式支持第三方客戶端的cookie-auth,所以你真的應該看看OAuth。 – bboe