python - PyJWT, Expecting a PEM-formatted key -


i have copy pasted code layer:

https://github.com/layerhq/support/blob/master/identity-services-samples/python/controller.py

i have been told 2 other people ran on mac machines. using windows 7, , getting typeerror: expecting pem-formatted key when running code:

#read rsa key root = os.path.dirname("__file__") open(os.path.join(root, rsa_key_path), 'r') rsa_priv_file:      #not sure adding utf-8 @     priv_rsakey = rsa.importkey(rsa_priv_file.read())  #create identity token #make sure have pyjwt , pycrypto libraries installed , imported identitytoken = jwt.encode(     payload={         "iss": provider_id,                 # string - provider id found in layer dashboard         "prn": user_id,                     # string - provider's internal id authenticating user         "iat": datetime.datetime.now(),              # integer - time of token issuance in rfc 3339 seconds         "exp": datetime.datetime.utcnow() + datetime.timedelta(seconds=30),   # integer - arbitrary token expiration in rfc 3339 seconds         "nce": nonce                        # nonce obtained via layer client sdk.     },     key=priv_rsakey,     headers = {         "typ": "jws",               # string - expresses mime type of application/jws         "alg": "rs256",             # string - expresses type of algorithm used sign token, must rs256         "cty": "layer-eit;v=1",     # string - express content type of layer external identity token, version 1         "kid": key_id               # string - private key associated "layer.pem", found in layer dashboard     },     algorithm="rs256" )  print identitytoken 

i not know how else pem formatted key should be, follows(i have manually changed key before posting):

-----begin rsa private key----- miicwwibaakbgqcwjll4hw8plto2wggxrpj0afhqdx2ij/xqnxyybgg0gxzi344u hxxn/brzh4z39pw3vgkrvd21hyln5/qajgocsb7qhatdz8pfnf3t96dbcdh2adme +8w/4mzqidi2znqxanmuv6vsknu3uyqfpupcdxfia8gt8oqhhlks8myyjwidaqab aogaii9i9yxshfighv1sq7l7102qjnk+hzocr33n8fe2crucofqptfp2mg8w3ect j/h4jn3lgvvzba+tdtipthi3rf1w4yns4po3xyljzhocdg5cjhomzef2vwixk6+f 8fccnerg8yxcpcpdh8d0njmfzj0t1kwsbq0w5isvdy3qtlecqqdgqpvk6w79kns9 gbozab71yjazqpcwj2slyj6afnzdx1jpg5grovos59gl13uf+9awjf5mcimbqaly t1/4aba1akeaq9y0dwsjnll26xebhwycqjzuu5lsjvqjcx2q0gskgx5ntei/48bd ldi7zxwda6o4oov2gpw1hx7vssphbxbyswjamgxukdlrawiagwvkpieklyfdbnmy 5uuzh3tsh1r36zjo9tyutf/dt026ghcnkomhy1xnxyeqyqetklh3hevzaqjaiqyc r1qtzedlaaeoaszq6/q3cek4545tbgswwuyghhl3kznldyiw8oc30xibfqxjsd0d qzqu0jcg9hg6f2gmewjalhz0jxhpjo+uygujdkbw/mfkrirsyiglcyqhinc4aade omr9xlu9hc6ai9rvgifmnygai9ahu2mnkpj5uoatta==

-----end rsa private key-----

i couldn't find solutions problem worked. have ideas? thanks

change:

priv_rsakey = rsa.importkey(rsa_priv_file.read()) 

to:

priv_rsakey = rsa_priv_file.read() 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -