title: PyJWT, Expecting a PEM-formatted key
body: <p>I have copy pasted this code from Layer:</p>
  <p><a href="https://github.com/layerhq/support/blob/master/identity-services-samples/python/controller.py" rel="nofollow noreferrer">https://github.com/layerhq/support/blob/master/identity-services-samples/python/controller.py</a></p>
  <p>I have been told two other people ran it successfully on mac machines. I am using a windows 7,  and I am getting the TypeError: Expecting a PEM-formatted key when running the code:</p>
  <pre><code>#Read RSA key
  root = os.path.dirname(&quot;__file__&quot;)
  with open(os.path.join(root, RSA_KEY_PATH), 'r') as rsa_priv_file:
      
      #Not sure about adding the utf-8 AT ALL
      priv_rsakey = RSA.importKey(rsa_priv_file.read())
  
  #Create identity token
  #Make sure you have PyJWT and PyCrypto libraries installed and imported
  identityToken = jwt.encode(
      payload={
          &quot;iss&quot;: PROVIDER_ID,                 # String - The Provider ID found in the Layer Dashboard
          &quot;prn&quot;: user_id,                     # String - Provider's internal ID for the authenticating user
          &quot;iat&quot;: datetime.datetime.now(),              # Integer - Time of Token Issuance in RFC 3339 seconds
          &quot;exp&quot;: datetime.datetime.utcnow() + datetime.timedelta(seconds=30),   # Integer - Arbitrary Token Expiration in RFC 3339 seconds
          &quot;nce&quot;: nonce                        # The nonce obtained via the Layer client SDK.
      },
      key=priv_rsakey,
      headers = {
          &quot;typ&quot;: &quot;JWS&quot;,               # String - Expresses a MIME Type of application/JWS
          &quot;alg&quot;: &quot;RS256&quot;,             # String - Expresses the type of algorithm used to sign the token, must be RS256
          &quot;cty&quot;: &quot;layer-eit;v=1&quot;,     # String - Express a Content Type of Layer External Identity Token, version 1
          &quot;kid&quot;: KEY_ID               # String - Private Key associated with &quot;layer.pem&quot;, found in the Layer Dashboard
      },
      algorithm=&quot;RS256&quot;
  )
  
  print identityToken
  </code></pre>
  <p>I do not know how else my PEM formatted key should be, but it is as follows(I have manually changed the key before posting):</p>
  <blockquote>
  <p>-----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==</p>
  <p>-----END RSA PRIVATE KEY-----</p>
  </blockquote>
  <p>I couldn't find any solutions to my problem that worked.
  Anyone have any ideas? Thanks</p>