vsakkas / sydney.py

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

sydney.exceptions.ThrottledRequestException: Request is throttled #133

Closed wdrink closed 6 months ago

wdrink commented 6 months ago

I installed sydney and have used it for several days. However, recently I always met an error:

"sydney.exceptions.ThrottledRequestException: Request is throttled". I wonder what I should do to fix this. Thanks!

vsakkas commented 6 months ago

Hi @wangjk666

Bing Chat has a limit on the amount of prompts you can send within a day. It seems that you've reached that limit for today.

There are some options here:

Hope that helps!

Mefisto4444 commented 6 months ago

@wangjk666 You can replace cookies with new ones to bypass this limit

from requests.cookies import RequestsCookieJar
import requests
import json 

def prepare_cookies(cookies:RequestsCookieJar):
    """Prepare cookies for sydney"""
    base_str =  json.dumps(dict(cookies.items()))
    return base_str.replace('{','').replace('}','').replace(',',';').replace(': ','=').replace('"','')

def get_new_cookies() -> RequestsCookieJar:
    """Returns new cookies to use in Bing Chat"""
    res = requests.get('https://www.bing.com/search?q=Bing+AI&showconv=1&FORM=hpcodx')
    return res.cookies

async with SydneyClient(style='Precise', bing_cookies=cookies) as sydney:
    #Your code
    except ThrottledRequestException:
        sydney.bing_cookies = prepare_cookies(get_new_cookies())
wdrink commented 6 months ago

Hi @vsakkas @Mefisto4444 Thanks very much for your help. I tried as you suggested but still failed, sydney keeps throwing the above error.

async with SydneyClient(style='Precise', bing_cookies=cookies) as sydney:
        suc = False
        try_times = 5

        while not suc and try_times > 0:
            try:
                response = await sydney.ask(this_prompt, img_url)
                suc = True
            except ThrottledRequestException:
                sydney.bing_cookies = prepare_cookies(get_new_cookies())
                try_times -= 1
Mefisto4444 commented 6 months ago

@wangjk666 If you can, send session cookies to Sydney without logging in to your Microsoft account. Check if the browser on your device can use Bing Chat. If not, it's an IP ban. You need to use a proxy

IKDH commented 6 months ago

The "Request is throttled" message means that your Microsoft account has reached the limit of 300 messages per day. Replacing the cookie won't help. Do the test and go to your Microsoft Copilote UI and try to send a message, you will see.

In order to bypass this, you have to use a different Microsoft account or use Bing Copilote without being connected to your Microsoft account.

wdrink commented 6 months ago

I use these functions to get a cookie:


def prepare_cookies(cookies:RequestsCookieJar):
    """Prepare cookies for sydney"""
    base_str =  json.dumps(dict(cookies.items()))
    return base_str.replace('{','').replace('}','').replace(',',';').replace(': ','=').replace('"','')

def get_new_cookies() -> RequestsCookieJar:
    """Returns new cookies to use in Bing Chat"""
    res = requests.get('https://www.bing.com/search?q=Bing+AI&showconv=1&FORM=hpcodx')

I think I don't get access to Copilot with my Microsoft account, right?

Mefisto4444 commented 6 months ago

No, but if you import cookies from browser where you are logged to Microsoft account and then use these functions then It might cause some troubles

vsakkas commented 6 months ago

No, but if you import cookies from browser where you are logged to Microsoft account and then use these functions then It might cause some troubles

I don't know how true this is in practice, though. I have been developing this library for several months, using my personal account without getting banned. I occasionally get throttled, but that's just part of the development.

That being said, if using the library without cookies if without logging in works, then that's great!

wdrink commented 6 months ago

I agree with you. But if I don't get access to Copilot with my Microsoft account, why I could "reached the limit of 300 messages per day.". I wonder whether it's most likely that my IP is banned (but I tried on multiple machines and all failed with "throttled" error. Soooo sad < _ <

vsakkas commented 6 months ago

Hm, if the "throttled" error persist even after a couple of days have passed, then it might indeed be an IP ban, in which case using a proxy should be a good workaround.

wdrink commented 6 months ago

Ok. Thanks a lot for your kind reply and help. I think this tool is pretty great!

Mefisto4444 commented 6 months ago

@IKDH but what if you use cookies from not logged session? Then after reaching limit from one cookie you should be able reset cookies and reach the limit again

Mefisto4444 commented 6 months ago

@wangjk666 @vsakkas I am using this tool with cookies from NOT logged session and I have limit of 30 messages without throttling. However if I reset cookies within the same SydneyClient using my functions from above I gain another 30 messages. Repeating this cycle gives me unlimited access to copilot

wdrink commented 6 months ago

https://github.com/vsakkas/sydney.py/issues/133#issuecomment-1858491418 You mean with these two functions you could own unlimited access to copilot? That's weird, I always fail.

Mefisto4444 commented 6 months ago

Try to copy my approach exactly the same from above and see if that helps

wdrink commented 6 months ago

I tried your code (see https://github.com/vsakkas/sydney.py/issues/133#issuecomment-1858662298) but still fail.

Mefisto4444 commented 6 months ago

@wangjk666 @vsakkas I am using this tool with cookies from NOT logged session and I have limit of 30 messages without throttling. However if I reset cookies within the same SydneyClient using my functions from above I gain another 30 messages. Repeating this cycle gives me unlimited access to copilot

Try exactly this approach. Don't change any step.

IKDH commented 6 months ago

@IKDH but what if you use cookies from not logged session? Then after reaching limit from one cookie you should be able reset cookies and reach the limit again

I will try and let you know ! By the way, have you been able to run this on a server like AWS or are you running it on a computer ?

Mefisto4444 commented 6 months ago

@IKDH but what if you use cookies from not logged session? Then after reaching limit from one cookie you should be able reset cookies and reach the limit again

I will try and let you know ! By the way, have you been able to run this on a server like AWS or are you running it on a computer ?

PC windows 10

IKDH commented 6 months ago

@Mefisto4444 it doesn't work with non logged session cookie. I get a captcha error but any captcha appear in the Microsoft Bing Chat UI. So I can't solve it.

Mefisto4444 commented 6 months ago

@IKDH If you get captcha when trying to get new non logged session cookie then use curl_cffi instead of requests. But if this is sydney problem then there is nothing we can do about this ;(. Maybe the thing with required logged session cookies is country based issue.

IKDH commented 6 months ago

@Mefisto4444 I don't know if it is related to my country because I can use Bing chat without being logged in. But with the script, it triggers a captcha. In which country are you ? I will try with a VPN from your country.

Mefisto4444 commented 6 months ago

Poland

IKDH commented 6 months ago

@Mefisto4444 I had made some test. I can generate cookies with your script but when I use them on this librairy, i get this error : Failed to create conversation, received status: 404. If I use logged in session cookies, it is working.

Mefisto4444 commented 6 months ago

Unfortunately after long amount of time my method seems to be ignored by Bing Chat and reseting cookies doesn't help. In my free time I will try to test different request params or maybe entirely change http client for something more stealthy like curl_cffi. I really hope it is not ip based throttling

IKDH commented 6 months ago

If it's IP base throttling, you can easely bypass it with a residential rotating proxy like Smartproxy.

What error do you get now ?

Mefisto4444 commented 6 months ago

sydney.exceptions.ThrottledRequestException: Request is throttled. It's weird because the limit should reset after switching cookies. Sleeping 30 secs changes nothing. I will later try to modify request params or change http client for httpx or curl_cffi

IKDH commented 6 months ago

You can try with a residential proxy. It may solve the problem.

Mefisto4444 commented 6 months ago

Yes, but with browser you can reset cookies and use it without any limits. I think the goal should be to replicate this but with http requests without proxy. However if nothing will work, using proxy will be the only way

IKDH commented 6 months ago

I see. I don't understand why I can use it without being logged in with my computer but not when i try your method, i get a 404 error. I have the same error if I use the librairie without a cookie.