imyizhang / Suno-API

Unofficial API for Suno AI: make a song with Suno using v3 🥳
https://pypi.org/project/suno-api/
BSD 3-Clause "New" or "Revised" License
36 stars 6 forks source link

Can't create client with a cookie. HTTP 403 response #4

Open hhauschild opened 2 months ago

hhauschild commented 2 months ago

The line command suno.Suno(cookie=suno_cookie) always returns the following exception for me:

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
Cell In[16], [line 2](vscode-notebook-cell:?execution_count=16&line=2)
      [1](vscode-notebook-cell:?execution_count=16&line=1) # Create a client
----> [2](vscode-notebook-cell:?execution_count=16&line=2) client = suno.Suno(cookie=suno_cookie)
      [3](vscode-notebook-cell:?execution_count=16&line=3) credits = client.get_credits()
      [4](vscode-notebook-cell:?execution_count=16&line=4) print(f"credits before song generation: {credits} ")

File [c:\Users\***\AppData\Local\Programs\Python\Python312\Lib\site-packages\suno\suno.py:78](file:///C:/Users/***/AppData/Local/Programs/Python/Python312/Lib/site-packages/suno/suno.py:78), in Suno.__init__(self, cookie)
     [76](file:///C:/Users/***/AppData/Local/Programs/Python/Python312/Lib/site-packages/suno/suno.py:76)     raise Exception("environment variable SUNO_COOKIE is not set")
     [77](file:///C:/Users/***/AppData/Local/Programs/Python/Python312/Lib/site-packages/suno/suno.py:77) super().__init__(cookie)
---> [78](file:///C:/Users/***/AppData/Local/Programs/Python/Python312/Lib/site-packages/suno/suno.py:78) self._sid = self._get_sid()
     [79](file:///C:/Users/***/AppData/Local/Programs/Python/Python312/Lib/site-packages/suno/suno.py:79) self.songs = Songs(self)

File [c:\Users\***\AppData\Local\Programs\Python\Python312\Lib\site-packages\suno\suno.py:85](file:///C:/Users/***/AppData/Local/Programs/Python/Python312/Lib/site-packages/suno/suno.py:85), in Suno._get_sid(self)
     [83](file:///C:/Users/***/AppData/Local/Programs/Python/Python312/Lib/site-packages/suno/suno.py:83) response = super().request("GET", url)
     [84](file:///C:/Users/***/AppData/Local/Programs/Python/Python312/Lib/site-packages/suno/suno.py:84) if not response.ok:
---> [85](file:///C:/Users/***/AppData/Local/Programs/Python/Python312/Lib/site-packages/suno/suno.py:85)     raise Exception(f"failed to get SID: {response.status_code}")
     [86](file:///C:/Users/***/AppData/Local/Programs/Python/Python312/Lib/site-packages/suno/suno.py:86) data = response.json()
     [87](file:///C:/Users/***/AppData/Local/Programs/Python/Python312/Lib/site-packages/suno/suno.py:87) return data.get("response").get("last_active_session_id")

Exception: failed to get SID: 403

I got my cookie from the Request "https://clerk.suno.com/v1/client?_clerk_js_version=4.72.0-snapshot.vc141245" out of the Chrome browser, which seems to be what the screenshot in the quickstart documentation suggests. I have tried Cookies from other requests too and made sure that they were not older that a minute or so. I have updated suno-api to version 0.1.2, but that did not fix the problem.

The problematic request seems to be a GET "https://clerk.suno.ai/v1/client?_clerk_js_version=4.70.5". When I open this URL in the browser, it is blocked by Cloudflare ("The action you just performed triggered the security solution. "). When I open https://clerk.suno.com/v1/client?_clerk_js_version=4.72.0-snapshot.vc141245 instead, I get a valid response. So the version-id in the URL seems to be the problem. Not sure if this is only a temporary issue, but it persists for some days now.

hhauschild commented 2 months ago

To correct myself: the problem was not the version string, but the host name clerk.suno.ai instead of clerk.suno.com.