0

I'm creating a website on a static server (Github Pages) and am trying to call the Spotify API to obtain my most recently played track. I think the issue I'm having is that I'm having trouble entering the authorization token

This is the code I tried - look at the 'response = await' line:

<py-script>
      from pyodide.http import pyfetch
      import json
      import asyncio
      import re
      response = await pyfetch(url="https://api.spotify.com/v1/me/player/currently-playing", headers = {'authorization': --insert auth token here--} , method="GET")
      cal= str('C')
      output = f'{await response.json()}'
      def jj(output):

        str1 = output.replace("\'", "\"")
        st= json.loads(str1)

        return st
      
      pyscript.write(jj(output))

          </py-script>

I end up getting a 'JsException(PythonError: Traceback (most recent call last): File "/lib/python3.10/asyncio/futures.py", line 201, in result raise self._exception File "/lib/python3.10/asyncio/tasks.py", line 232, in __step result = coro.send(None) File "/lib/python3.10/site-packages/_pyodide/_base.py", line 500, in eval_code_async await CodeRunner( File "/lib/python3.10/site-packages/_pyodide/_base.py", line 353, in run_async await coroutine File "", line 7, in File "/lib/python3.10/site-packages/pyodide/http.py", line 139, in json self._raise_if_failed() File "/lib/python3.10/site-packages/pyodide/http.py", line 107, in _raise_if_failed raise OSError( OSError: Request for https://api.spotify.com/v1/me/player/currently-playing failed with status 400: )'

1 Answers1

0

What version of PyScript are you using? Using top-level await like that was removed in Version 2022.12.1. The answer to your question will depend on which version of PyScript (and therefore which version of Pyodide) you are using.

(Apologies - this should be a comment, but I do not yet have the required reputation here.)

Jeff Glass
  • 622
  • 1
  • 8