我寫,我需要通過API V2連接到MtGox(一個比特幣交易所)交易程序。不過,我不斷收到以下錯誤:問題連接到MtGox API 2與Python
URL: 1 https://data.mtgox.com/api/2/BTCUSD/money/bitcoin/address
HTTP Error 403: Forbidden.
大多數我的劇本是從here直接複製(這是一個引擎收錄鏈接)。我只是不得不改變它與Python 3.3一起工作。
我懷疑它有腳本的一部分,我用base64.b64encode做。 In my code,我有編碼我的琴絃爲UTF-8使用base64.b64encode:
url = self.__url_parts + '2/' + path
api2postdatatohash = (path + chr(0) + post_data).encode('utf-8') #new way to hash for API 2, includes path + NUL
ahmac = base64.b64encode(str(hmac.new(base64.b64decode(self.secret),api2postdatatohash,hashlib.sha512).digest()).encode('utf-8'))
# Create header for auth-requiring operations
header = {
"User-Agent": 'Arbitrater',
"Rest-Key": self.key,
"Rest-Sign": ahmac
}
然而,與其他人的劇本,他並沒有太多:
url = self.__url_parts + '2/' + path
api2postdatatohash = path + chr(0) + post_data #new way to hash for API 2, includes path + NUL
ahmac = base64.b64encode(str(hmac.new(base64.b64decode(self.secret),api2postdatatohash,hashlib.sha512).digest()))
# Create header for auth-requiring operations
header = {
"User-Agent": 'genBTC-bot',
"Rest-Key": self.key,
"Rest-Sign": ahmac
}
我想知道如果額外的編碼導致我的頭憑證不正確。我認爲這是另一個Python 2 v。Python 3問題。我不知道其他人是怎麼走而不改變爲UTF-8,因爲如果你試圖傳遞一個字符串到b64encode或HMAC腳本將不會運行。你們看到我在做什麼有什麼問題嗎?相當於代碼嗎?