Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 TypeError: must be str, not bytes
Well, I don't know what API will use a base64 encoded key. Since it is a secret key I won't ask you to put it here. If you want to change it but and at the same time preserve the "structure"...

base64.b64decode can't decode the API_SECRET value. Is it base64 encoded at the first? See what base64 is. Read it carefully. I will do it too when I have time for this. I am not so aware how it works exactly too.

See what Output padding is.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
Thank you very much.
I will be studying.

The code has
API_SECRET = 'KY9R6bgPfQeDr2kV...rwm4aoGk0EvQwU...eduafbsk' 
it is encrypted apparently. I changed it for the forum. But I have error with full key.
Well, these guys have a forum. And I've found this post. The code for Python 3 looks a bit different.

Generate a new API key. You had to randomize the API_SECRET.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
Thank you very much.
Yes, the code I tried and did something when there were mistakes. Now it seems to have received a response from the server, but not the kind who waited

import urllib
from urllib.request import urlopen
import json
import time
import hmac,hashlib
import random
import base64

class cryptopia:
        def __init__(self, key='', secret='', url=''):
                self.apikey = key
                self.apisecret = secret
                self.apisite = url
                self.api_params = {}
        def public_api(self, meth):
                return json.loads(urlopen(urlopen(self.apisite + meth)).read())
        def private_api(self, method, values={}, req={}):
                if method in self.private:
                        url = "" + method
                        nonce = str(int(time.time()))
                        requestContentBase64String = base64.b64encode(hashlib.md5(json.dumps(values)).digest())
                        signature = self.key + "POST" + urllib.quote_plus(url).lower() + nonce + requestContentBase64String
                        hmacsignature = base64.b64encode(, signature, hashlib.sha256).digest())
                        header_value = "amx " + self.key + ":" + hmacsignature + ":" + nonce
                        headers = { 'Authorization': header_value }
                        r =, json = values, headers=headers)
                elif method in self.public:
                        url = '' + method 
                        r = requests.get(url, params=values) 
                        return 'Call Not Identified - Something Went Wrong.'
                response = r.content
                print ("( Response ): " + response)
                return response.replace("false","False").replace("true","True").replace('":null','":None' )
        def getCurrencies(self):
                return self.public_api('GetCurrencies')
        def getTradePairs(self):
                return self.public_api('GetTradePairs')
        def getBalances(self):
                return self.private_api('GetBalance')
API_KEY = 'ac85417173...abdf98138e...02'
API_SECRET = 'KY9R6bgPfQeDr2kV...rwm4aoGk0EvQwU...eduafbsk'

my_api = cryptopia(API_KEY, API_SECRET)

# test public api call
#print (my_api.getMarketOrders)

# test private api call
print (my_api.getBalances)

<bound method cryptopia.getBalances of <__main__.cryptopia object at 0x0205E0B0>>
It tells you that it is a method, not an attribute. You have to call it.
print (my_api.getBalances()) # do you see the parenthesis?
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Packet Sniffer - TypeError: a bytes-like object is required, not 'str' cheffa2020 4 281 Jun-12-2020, 02:10 PM
Last Post: cheffa2020
  TypeError: a bytes-like object is required, not 'str' - Help Please. IanJ 1 371 May-19-2020, 07:15 PM
Last Post: Larz60+
  Why, TypeError: expected string or bytes-like object ? JohnnyCoffee 3 639 May-08-2020, 04:26 AM
Last Post: bowlofred
  TypeError: a bytes-like object is required, not 'str'. jacklee26 4 525 Apr-18-2020, 11:04 PM
Last Post: jacklee26
  replace bytes with other byte or bytes BigOldArt 1 992 Feb-02-2019, 11:00 PM
Last Post: snippsat
  builtins.TypeError: a bytes-like object is required, not 'str' BigOldArt 0 1,759 Jan-31-2019, 10:46 PM
Last Post: BigOldArt
  TypeError: initial_value must be str or None, not bytes PeterPython 2 7,057 Aug-12-2018, 03:58 PM
Last Post: PeterPython
  TypeError: initial_value must be str or None, not bytes new2py 4 6,497 Aug-31-2017, 12:23 AM
Last Post: new2py

Forum Jump:

Users browsing this thread: 1 Guest(s)