FireHead90544 / craiyon.py

Unofficial API Wrapper for craiyon.com (DAL-E-MINI). Generate awesome images from text tokens.
Apache License 2.0
69 stars 22 forks source link

Json Decode Error #19

Closed IntelligenzaArtificiale closed 9 months ago

IntelligenzaArtificiale commented 1 year ago

Hi guys, i have a problem.

File "/mount/src/generatore-arte-ia/Craiyon.py", line 13, in Generate
    result = generator.generate(request)
File "/home/adminuser/venv/lib/python3.9/site-packages/craiyon/craiyon.py", line 182, in generate
    return GeneratedImages(resp.json()['images'], model="v1")
File "/home/adminuser/venv/lib/python3.9/site-packages/requests/models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

I have try v3 and v1 in all version ( async and not) and the result is always this .

How i can resolve ?

FireHead90544 commented 1 year ago

Refer to this issue: #17 Will be trying to update asap

IntelligenzaArtificiale commented 1 year ago

Hi, there's news? I keep getting this error.

NormVg commented 1 year ago
generated_images = await generator.async_generate(prompt)

File "C:\Program Files\Python310\lib\site-packages\craiyon\craiyon.py", line 76, in async_generate resp = await resp.json() File "C:\Program Files\Python310\lib\site-packages\aiohttp\client_reqrep.py", line 1104, in json raise ContentTypeError( aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8', url=URL('https://api.craiyon.com/v3')

BenGuerre commented 1 year ago

Do you an example with aiocfscrape?

RodriCalle commented 1 year ago

Hi guys. I have the same problem using call async. Here is more information <ClientResponse(api_url) [403 Forbidden]> <CIMultiDictProxy('Date': 'Fri, 27 Oct 2023 00:16:41 GMT', 'Content-Type': 'text/html; charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Cache-Control': 'max-age=15', 'Expires': 'Fri, 27 Oct 2023 00:16:56 GMT', 'Set-Cookie': '__cf_bm=Uefam2y9XxIuOusIhlihIjiwPpUx6oN4QAxT2O9Kx1s-1698365801-0-AcD2FIT4Ij2wBjMscSR8gkK2FK3agmtpoUgNuSIL7mawOAylw37/QgHS2MDTgD9tfaYtTl1nWP/GXnnUu0T3V0A=; path=/; expires=Fri, 27-Oct-23 00:46:41 GMT; domain=.craiyon.com; HttpOnly; Secure; SameSite=None', 'Vary': 'Accept-Encoding', 'expect-ct': 'max-age=86400, enforce', 'referrer-policy': 'same-origin', 'x-content-type-options': 'nosniff', 'x-frame-options': 'SAMEORIGIN', 'x-xss-protection': '1; mode=block', 'Server': 'cloudflare', 'CF-RAY': '81c6c0736dff4952-TPA', 'Content-Encoding': 'gzip')>

If anyone know how to solve it, please help me.

HumanBot000 commented 11 months ago
generator = Craiyon()
            result = await generator.async_generate(prompt)
        aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8', url=URL('https://api.craiyon.com/v3')
PythonX-001 commented 11 months ago
generator = Craiyon()
            result = await generator.async_generate(prompt)
        aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8', url=URL('https://api.craiyon.com/v3')

did you solve it or what ??

FireHead90544 commented 9 months ago

Just released v1.2.0.

Removed the cloudscraper dependency and switched to using headers. v1 and v3 endpoints are now working as expected. I didn't perform many tests but v3 seems to work normally (5/5 passes) while v1 (2/5 passes) sometimes seems to cause JSONDecodeError because of cloudflare's security page. So I'd suggest either use it inside a try-catch block and repeat the request or just don't use the v1 model.

Update your wrappers by running pip install -U craiyon.py, and reopen the issue if you think the problem still persists.