vsakkas / sydney.py

Python Client for Copilot (formerly named Bing Chat), also known as Sydney.
MIT License
263 stars 37 forks source link

Still getting a Captcha exception #76

Closed regstuff closed 10 months ago

regstuff commented 11 months ago

Hello, I've followed the instructions and even entered a new cookie each time (by logging in and out in the browser), but I still get raise CaptchaChallengeException("Solve CAPTCHA to continue") Any way around this?

vsakkas commented 11 months ago

Hi @regstuff

Thank you for raising this issue. Unfortunately, it seems that I cannot reproduce this issue on my setup. Before you got the cookies, did you make sure to write a message to Bing Chat on the browser itself? Sometimes, it is necessary to do that before you can actually use the cookies. Also, make sure you're using the cookies from edgeservices.bing.com.

regstuff commented 11 months ago

Yes I followed the procedure to get the cookie. It is from edgeservices.bing.com and I am taking it after I write a message. Tried with a different Edge profile and also on a different laptop. But no luck. This is the code I'm using. Do you see anything wrong here? (Have cut out the cookie details for privacy)

import asyncio, os
from sydney import SydneyClient

os.environ["BING_U_COOKIE"] = "1...A"

async def main():
    async with SydneyClient(style="creative") as sydney:
        response = await sydney.ask("When was Bing Chat released?", citations=True)
        print(response)

if __name__ == "__main__":
    asyncio.run(main())

Here's the full error:

Traceback (most recent call last):
  File "D:\Code\bingchat\sidney_test.py", line 12, in <module>
    asyncio.run(main())
  File "C:\Program Files\Python39\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 647, in run_until_complete
    return future.result()
  File "D:\Code\bingchat\sidney_test.py", line 8, in main
    response = await sydney.ask("When was Bing Chat released?", citations=True)
  File "D:\Code\bingchat\bingchat\lib\site-packages\sydney\sydney.py", line 459, in ask
    async for response, suggested_responses in self._ask(
  File "D:\Code\bingchat\bingchat\lib\site-packages\sydney\sydney.py", line 374, in _ask
    raise CaptchaChallengeException("Solve CAPTCHA to continue")
sydney.exceptions.CaptchaChallengeException: Solve CAPTCHA to continue
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x00000235DD7B95E0>
Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Program Files\Python39\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 751, in call_soon
    self._check_closed()
  File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 515, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
vsakkas commented 11 months ago

Hi @regstuff I tested your code on my laptop and it worked for me. At first I was also receiving the same error, but I got a new cookie and it fixed the problem.

A few of suggestions:

regstuff commented 11 months ago

Hi. Tried all of these, but no luck. :( Not sure what you mean by the Success! message from Bing Chat. I take the cookies after sending a message and receiving a reply in the Edge sidebar. Here's a screenshot Capture

IKDH commented 11 months ago

You should

  1. Run your script with a cookie and get a captcha error
  2. Go to the bing chat session related to this cookie
  3. Send a random message
  4. Then you should see the captcha box appear and validate it
  5. Run your script again

It works for me.

IKDH commented 11 months ago

By the way, @vsakkas, in my region, I am able to discuss with Bing Chat in private navigation (without U cookie) but when I set up the cookie as optional in the script, it raised a captcha. Do you know how to solve that ?

vsakkas commented 11 months ago

Hi @IKDH This is something that I am interested in looking at. I am doing some testing using incognito mode to better understand the differences between using the cookie and without. From a first look, indeed, there are some subtle differences in the request payload, so I will investigate to see if that changes anything.

vsakkas commented 11 months ago

Well, it's a bit weird. One of the differences between using cookies and not using cookies is that when you use Bing Chat in incognito, the sliceIds field has a bunch of values. But they change every time I open a new browser window and start a conversation... I will focus for now on other parts of the request

vsakkas commented 11 months ago

@IKDH I am still looking into this, but lately I am getting throttled quite a lot which makes it hard to test anything. Hopefully, I will be able to come up with an MR for this soon :crossed_fingers:

IKDH commented 11 months ago

You are getting throttled in Incognito mode ?

vsakkas commented 11 months ago

Not in incognito, but with cookies (which the test suite uses) which I use often to test things

IKDH commented 11 months ago

You can easily link 4+ mails to Microsoft Bing. So when one is getting throttled, you can switch to the other. I think you can do 300 requests per day per account.

vsakkas commented 11 months ago

That's a good suggestion! I might set up a second account to grab cookies just for the test suite

vsakkas commented 10 months ago

0.18.0 brings new improvements when it comes to using Sydney.py with cookie, I believe it should fix the Captcha related issues