Giter Club home page Giter Club logo

pychatgpt's Issues

Cloudflare challenge failed

console output

ValueError: Cloudflare challenge failed:

{"user":{"id":"","name":"","email":"","image":"","picture":"","groups":[],"features":[]},"expires":"2023-01-13T02:58:04.509Z","accessToken":""}

Note: personal information has been deleted.

Cloudflare issue

Hello Terry
Thanks for your work - it seemed like they now using Cloudflare any chance you could do a bypass or something?
Or is it just me ran into the Cloudflare issue?

</div>
            <div class="text-center">Performance &amp; security by <a rel="noopener noreferrer" href="https://www.cloudflare.com?utm_source=challenge&utm_campaign=m" target="_blank">Cloudflare</a></div>
        </div>
    </div>
</body>
</html>

list index out of range

Error: list index out of range

Version: 0.3.9.4


File "pyChatGPT.py", line 395, in send_message
    response = self.driver.find_elements(
IndexError: list index out of range

TimeoutException. I tried to set longer time such as 35, it still doesnt work

Hi, I run my script on a VPS with debian 11, chrome=108.0.5359.94, xvfb=2:1.20.11-1.

  1. when i run the code python chat_test.py, i got error selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:39123 from chrome not reachable
 File "/root/miniconda3/lib/python3.9/site-packages/pyChatGPT/pyChatGPT.py", line 108, in __init_browser
   self.driver = uc.Chrome(options=options, enable_cdp_events=True)
 File "/root/miniconda3/lib/python3.9/site-packages/undetected_chromedriver/__init__.py", line 429, in __init__
   super(Chrome, self).__init__(
 File "/root/miniconda3/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
   super().__init__(
 File "/root/miniconda3/lib/python3.9/site-packages/selenium/webdriver/chromium/webdriver.py", line 106, in __init__
   super().__init__(
 File "/root/miniconda3/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 288, in __init__
   self.start_session(capabilities, browser_profile)
 File "/root/miniconda3/lib/python3.9/site-packages/undetected_chromedriver/__init__.py", line 715, in start_session
   super(selenium.webdriver.chrome.webdriver.WebDriver, self).start_session(
 File "/root/miniconda3/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 381, in start_session
   response = self.execute(Command.NEW_SESSION, parameters)
 File "/root/miniconda3/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 444, in execute
   self.error_handler.check_response(response)
 File "/root/miniconda3/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 249, in check_response
   raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:49773
from chrome not reachable
Stacktrace:
#0 0x5625cfe822a3 <unknown>
  1. Then i excute xvfb-run -a python chat_test.py and got this error selenium.common.exceptions.WebDriverException: Message: unknown error: failed to change window state to 'minimized', current state is 'normal'
(base) root@adalee:~# xvfb-run -a python chat_test.py 
Traceback (most recent call last):
  File "/root/chat_test.py", line 3, in <module>
    api = ChatGPT(auth_type='google', email='****@gmail.com', password='*****') # auth with google login
  File "/root/miniconda3/lib/python3.9/site-packages/pyChatGPT/pyChatGPT.py", line 66, in __init__
    self.__init_browser()
  File "/root/miniconda3/lib/python3.9/site-packages/pyChatGPT/pyChatGPT.py", line 131, in __init_browser
    self.__ensure_cf()
  File "/root/miniconda3/lib/python3.9/site-packages/pyChatGPT/pyChatGPT.py", line 271, in __ensure_cf
    self.driver.minimize_window()
  File "/root/miniconda3/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 619, in minimize_window
    self.execute(Command.MINIMIZE_WINDOW)
  File "/root/miniconda3/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 444, in execute
    self.error_handler.check_response(response)
  File "/root/miniconda3/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 249, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: failed to change window state to 'minimized', current state is 'normal'
  (Session info: chrome=108.0.5359.94)
Stacktrace:
#0 0x565158c992a3 <unknown>
#1 0x565158a57f77 <unknown>
#2 0x565158a36f83 <unknown>
#3 0x565158a35c43 <unknown>
#4 0x565158a3634f <unknown>
#5 0x565158adf5c6 <unknown>
#6 0x565158ab4b32 <unknown>
#7 0x565158acc47c <unknown>
#8 0x565158ab4903 <unknown>
#9 0x565158a87ece <unknown>
#10 0x565158a88fde <unknown>
#11 0x565158ce963e <unknown>
#12 0x565158cecb79 <unknown>
#13 0x565158ccf89e <unknown>
#14 0x565158ceda83 <unknown>
#15 0x565158cc2505 <unknown>
#16 0x565158d0eca8 <unknown>
#17 0x565158d0ee36 <unknown>
#18 0x565158d2a333 <unknown>
#19 0x7f4ddfcedea7 start_thread
  1. I think it's caused by this line, and just delete and 'DISPLAY' not in os.environ
    platform.system() == 'Linux' and 'DISPLAY' not in os.environ

    image

then, i got the following error TimeoutException. I tried set longer time such as 35, it still didn't work:

(base) root@adalee:~# xvfb-run -a python chat_test.py 
Platform: Linux
Display: True
Headless: True
Starting virtual display
Starting browser
Ensuring Cloudflare challenge
Opening new tab
Getting authorization
Cloudflare challenge failed, retrying 1
Closing tab
Opening new tab
Getting authorization
Authorization is empty
Opening new tab
Opening login page
Checking if ChatGPT is at capacity
ChatGPT is at capacity, retrying
Checking if ChatGPT is at capacity
Clicking Log in button
Clicking Google button
Checking if Google remembers email
Google does not remember email
Entering email
Clicking Next
Entering password
Clicking Next
Checking if verification code is required
Checking if login was successful
Traceback (most recent call last):
  File "/root/miniconda3/lib/python3.9/site-packages/pyChatGPT/pyChatGPT.py", line 277, in __ensure_cf
    WebDriverWait(self.driver, 15).until(
  File "/root/miniconda3/lib/python3.9/site-packages/selenium/webdriver/support/wait.py", line 95, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 
Stacktrace:
#0 0x559f460a62a3 <unknown>
#1 0x559f45e64f77 <unknown>
#2 0x559f45ea180c <unknown>
#3 0x559f45ea1a71 <unknown>
#4 0x559f45edb734 <unknown>
#5 0x559f45ec1b5d <unknown>
#6 0x559f45ed947c <unknown>
#7 0x559f45ec1903 <unknown>
#8 0x559f45e94ece <unknown>
#9 0x559f45e95fde <unknown>
#10 0x559f460f663e <unknown>
#11 0x559f460f9b79 <unknown>
#12 0x559f460dc89e <unknown>
#13 0x559f460faa83 <unknown>
#14 0x559f460cf505 <unknown>
#15 0x559f4611bca8 <unknown>
#16 0x559f4611be36 <unknown>
#17 0x559f46137333 <unknown>
#18 0x7f6227a5cea7 start_thread

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/miniconda3/lib/python3.9/site-packages/pyChatGPT/pyChatGPT.py", line 248, in __login
    WebDriverWait(self.driver, 5).until(
  File "/root/miniconda3/lib/python3.9/site-packages/selenium/webdriver/support/wait.py", line 95, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 
Stacktrace:
#0 0x559f460a62a3 <unknown>
#1 0x559f45e64f77 <unknown>
#2 0x559f45ea180c <unknown>
#3 0x559f45ea1a71 <unknown>
#4 0x559f45edb734 <unknown>
#5 0x559f45ec1b5d <unknown>
#6 0x559f45ed947c <unknown>
#7 0x559f45ec1903 <unknown>
#8 0x559f45e94ece <unknown>
#9 0x559f45e95fde <unknown>
#10 0x559f460f663e <unknown>
#11 0x559f460f9b79 <unknown>
#12 0x559f460dc89e <unknown>
#13 0x559f460faa83 <unknown>
#14 0x559f460cf505 <unknown>
#15 0x559f4611bca8 <unknown>
#16 0x559f4611be36 <unknown>
#17 0x559f46137333 <unknown>
#18 0x7f6227a5cea7 start_thread

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/chat_test.py", line 3, in <module>
    api = ChatGPT(auth_type='google', email='******@gmail.com', password='******.', verbose=True) # auth with google login
  File "/root/miniconda3/lib/python3.9/site-packages/pyChatGPT/pyChatGPT.py", line 66, in __init__
    self.__init_browser()
  File "/root/miniconda3/lib/python3.9/site-packages/pyChatGPT/pyChatGPT.py", line 131, in __init_browser
    self.__ensure_cf()
  File "/root/miniconda3/lib/python3.9/site-packages/pyChatGPT/pyChatGPT.py", line 293, in __ensure_cf
    return self.__ensure_cf(retry + 1)
  File "/root/miniconda3/lib/python3.9/site-packages/pyChatGPT/pyChatGPT.py", line 303, in __ensure_cf
    self.__login()
  File "/root/miniconda3/lib/python3.9/site-packages/pyChatGPT/pyChatGPT.py", line 253, in __login
    raise ValueError('Login failed')

problem when send request with conversation_id

I send first message normal
like something = ChatGPT(email=email, password=pas)

and I want to continue in the same conversation so the second message I sent is like

something = ChatGPT(email=email, password=pas, conversation_id=conversation_id)

but this returns error {"detail":"Too many requests, please slow down"}
even If I wait between the two messages

urllib error

Traceback (most recent call last):
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 1350, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1010, in _send_output
    self.send(msg)
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 950, in send
    self.connect()
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1417, in connect
    super().connect()
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 921, in connect
    self.sock = self._create_connection(
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\socket.py", line 808, in create_connection
    raise err
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\socket.py", line 796, in create_connection
    sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "script.py", line 88, in <module>
    api = pyChatGPT(session_token)
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\site-packages\pyChatGPT\pyChatGPT.py", line 68, in __init__
    self.__init_browser()
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\site-packages\pyChatGPT\pyChatGPT.py", line 110, in __init_browser
    self.driver = uc.Chrome(options=options, enable_cdp_events=True)
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\site-packages\undetected_chromedriver\__init__.py", line 242, in __init__
    patcher.auto()
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\site-packages\undetected_chromedriver\patcher.py", line 127, in auto
    release = self.fetch_release_number()
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\site-packages\undetected_chromedriver\patcher.py", line 148, in fetch_release_number
    return LooseVersion(urlopen(self.url_repo + path).read().decode())
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 525, in open
    response = self._open(req, data)
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 502, in _call_chain
    result = func(*args)
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 1393, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "C:\Users\Lukmanul Hakim\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 1353, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond>

session token is str,but still met TypeError

session_token = 'eyJh....1y'
Why I set session_token str, but still met the TypeError?

Traceback (most recent call last):
  File "/home/ubuntu/work/chatgpt.py", line 8, in <module>
    api = ChatGPT(session_token)  # auth with session token
  File "/home/ubuntu/anaconda3/envs/chatgpt/lib/python3.9/site-packages/pyChatGPT/pyChatGPT.py", line 57, in __init__
    self.driver = uc.Chrome(options=options)
  File "/home/ubuntu/anaconda3/envs/chatgpt/lib/python3.9/site-packages/undetected_chromedriver/__init__.py", line 409, in __init__
    browser = subprocess.Popen(
  File "/home/ubuntu/anaconda3/envs/chatgpt/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/ubuntu/anaconda3/envs/chatgpt/lib/python3.9/subprocess.py", line 1696, in _execute_child
    and os.path.dirname(executable)
  File "/home/ubuntu/anaconda3/envs/chatgpt/lib/python3.9/posixpath.py", line 152, in dirname
    p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType

urllib.error.URLError: <urlopen error [WinError 10054] 远程主机强迫关闭了一个现有的连接。>

Traceback (most recent call last):
File "D:\python\lib\urllib\request.py", line 1348, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "D:\python\lib\http\client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "D:\python\lib\http\client.py", line 1328, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "D:\python\lib\http\client.py", line 1277, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "D:\python\lib\http\client.py", line 1037, in _send_output
self.send(msg)
File "D:\python\lib\http\client.py", line 975, in send
self.connect()
File "D:\python\lib\http\client.py", line 1454, in connect
self.sock = self._context.wrap_socket(self.sock,
File "D:\python\lib\ssl.py", line 513, in wrap_socket
return self.sslsocket_class._create(
File "D:\python\lib\ssl.py", line 1071, in _create
self.do_handshake()
File "D:\python\lib\ssl.py", line 1342, in do_handshake
self._sslobj.do_handshake()
ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\python\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "D:\python\lib\runpy.py", line 86, in run_code
exec(code, run_globals)
File "D:\python\lib\site-packages\pyChatGPT_main
.py", line 12, in
chat = ChatGPT(session_token)
File "D:\python\lib\site-packages\pyChatGPT\pyChatGPT.py", line 70, in init
self.__init_browser()
File "D:\python\lib\site-packages\pyChatGPT\pyChatGPT.py", line 112, in _init_browser
self.driver = uc.Chrome(options=options, enable_cdp_events=True)
File "D:\python\lib\site-packages\undetected_chromedriver_init
.py", line 242, in init
patcher.auto()
File "D:\python\lib\site-packages\undetected_chromedriver\patcher.py", line 127, in auto
release = self.fetch_release_number()
File "D:\python\lib\site-packages\undetected_chromedriver\patcher.py", line 148, in fetch_release_number
return LooseVersion(urlopen(self.url_repo + path).read().decode())
File "D:\python\lib\urllib\request.py", line 216, in urlopen
return opener.open(url, data, timeout)
File "D:\python\lib\urllib\request.py", line 519, in open
response = self._open(req, data)
File "D:\python\lib\urllib\request.py", line 536, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "D:\python\lib\urllib\request.py", line 496, in _call_chain
result = func(*args)
File "D:\python\lib\urllib\request.py", line 1391, in https_open
return self.do_open(http.client.HTTPSConnection, req,
File "D:\python\lib\urllib\request.py", line 1351, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [WinError 10054] 远程主机强迫关闭了一个现有的连接。>

Red Hat server chromium

I was going to run my file on a Red Hat AWS server. I tried to install chromium with the command you gave and some others I found online, each of them gave an error saying chrome wasn't found. How would I install it?

ValueError: Headless machine detected.

Hi All,

I am getting this error
"ValueError: Headless machine detected. Please install Xvfb to start a virtual display: sudo apt install xvfb"
I am using colab

Any one faced te same issue?

Thanks a lot

network error

when show long text, it will show network error,All text disappear
how to fix ,thks

list index out of range

chatgpt delete result-: starts
I use
markdown prose break-words dark:prose-invert light
instead
its ok

list index out of range

Each time I run, I get a 'list index out of range' error. That is actually all it gives me and in that exact format.

Feature Request: Authorization with both Session Token and Login

Is it possible to add a feature where if both a Session token and Login is provided use the session first, and if the token is either expired or invalid, fallback to login. This should be able to be done by just setting the session token and checking if the login screen appears.

Also a method to get the session token be added?
Currently using this:

config = chatgpt_get_config()

cookies_lst = chatgpt_instance.driver.execute_cdp_cmd(
    "Network.getCookies", {"urls": ["https://chat.openai.com/chat"]}
)["cookies"]

for cookie in cookies_lst:
    if cookie["name"] == "__Secure-next-auth.session-token":
        if cookie["value"] == config.get("session_token"):
            break
        logger.info("ChatBot - Saving session token")
        config["session_token"] = cookie["value"]
        chatgpt_set_config(config)
        break
else:
    logger.warning("ChatBot - Could not find session token")

Also, it would also be nice if there was a way to save the cloudflare token as well, but this isn't as necessary since logging in takes a lot longer.

IndexError: list index out of range

I'm using the most recent version pyChatGPT (the one updated 11 hours ago).

I'm getting the following error. Note, this error doesn't happen every time. Maybe 50% of the time.

Error:
line 606, in send_message response = self.driver.find_elements( IndexError: list index out of range

Anyone know why it's happening?

Invalid Session Token

I'm playing with this on macOS.

api = ChatGPT(SESSION_TOKEN)

... gives the following:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[3], line 1
----> 1 api = ChatGPT(SESSION_TOKEN)

File ~/code/2023/ML/hacking-chatGPT/.venv/lib/python3.11/site-packages/pyChatGPT/pyChatGPT.py:70, in ChatGPT.__init__(self, session_token, email, password, auth_type, proxy, verbose, window_size)
     68 self.__verbose_print('[0] Display:', 'DISPLAY' in os.environ)
     69 self.__verbose_print('[0] Headless:', self.__is_headless)
---> 70 self.__init_browser()

File ~/code/2023/ML/hacking-chatGPT/.venv/lib/python3.11/site-packages/pyChatGPT/pyChatGPT.py:135, in ChatGPT.__init_browser(self)
    133 # Ensure that the Cloudflare cookies is still valid
    134 self.__verbose_print('[init] Ensuring Cloudflare cookies')
--> 135 self.__ensure_cf()
    137 # Open the chat page
    138 self.__verbose_print('[init] Opening chat page')

File ~/code/2023/ML/hacking-chatGPT/.venv/lib/python3.11/site-packages/pyChatGPT/pyChatGPT.py:344, in ChatGPT.__ensure_cf(self, retry)
    342     self.__verbose_print('[cf] Authorization is empty')
    343     if not self.__auth_type:
--> 344         raise ValueError('Invalid session token')
    345     self.__login()
    346 self.__verbose_print('[cf] Authorization is valid')

ValueError: Invalid session token

Before erroring, it's opening up a Chrome window:

Screenshot 2022-12-22 at 04 03 50

Screenshot 2022-12-22 at 04 05 57

Screenshot 2022-12-22 at 04 06 12

Now my SessionToken is 100% correct. It's the cookie value for key intercom-session-dgkjq2bp.

PS Arriving from https://www.youtube.com/watch?v=lBCoktYvSKg&ab_channel=BhaveshBhatt
PPS You don't have a Discord do you?

WebDriverException: Message: unknown error: failed to change window state to 'minimized', current state is 'normal'

I am now getting this error in Google Colab as well as on my Ubuntu Machine (it worked flawlessly this afternoon):

WARNING:urllib3.connectionpool:Connection pool is full, discarding connection: localhost. Connection pool size: 1

WebDriverException Traceback (most recent call last)
in
8 session_token = 'XX I deleted this XX'
9
---> 10 api = ChatGPT(session_token) # auth with session token
11 #api2 = ChatGPT(email='[email protected]', password='password') # auth with email and password
12 #api3 = ChatGPT(session_token, conversation_id='some-random-uuid', parent_id='another-random-uuid') # specify a conversation

5 frames
/usr/local/lib/python3.8/dist-packages/pyChatGPT/pyChatGPT.py in init(self, session_token, email, password, auth_type, proxy, verbose)
64 self.__verbose_print('Display:', 'DISPLAY' in os.environ)
65 self.__verbose_print('Headless:', self.__is_headless)
---> 66 self.__init_browser()
67
68 def __verbose_print(self, *args, **kwargs) -> None:

/usr/local/lib/python3.8/dist-packages/pyChatGPT/pyChatGPT.py in __init_browser(self)
129 # Ensure that the Cloudflare challenge is still valid
130 self.__verbose_print('Ensuring Cloudflare challenge')
--> 131 self.__ensure_cf()
132
133 # Open the chat page

/usr/local/lib/python3.8/dist-packages/pyChatGPT/pyChatGPT.py in __ensure_cf(self, retry)
269 self.driver.switch_to.new_window('tab')
270 if not self.__is_headless:
--> 271 self.driver.minimize_window()
272
273 # Get the Cloudflare challenge

/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py in minimize_window(self)
617 Invokes the window manager-specific 'minimize' operation
618 """
--> 619 self.execute(Command.MINIMIZE_WINDOW)
620
621 def print_page(self, print_options: Optional[PrintOptions] = None) -> str:

/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py in execute(self, driver_command, params)
442 response = self.command_executor.execute(driver_command, params)
443 if response:
--> 444 self.error_handler.check_response(response)
445 response["value"] = self._unwrap_value(response.get("value", None))
446 return response

/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/errorhandler.py in check_response(self, response)
247 alert_text = value["alert"].get("text")
248 raise exception_class(message, screen, stacktrace, alert_text) # type: ignore[call-arg] # mypy is not smart enough here
--> 249 raise exception_class(message, screen, stacktrace)

WebDriverException: Message: unknown error: failed to change window state to 'minimized', current state is 'normal'
(Session info: chrome=108.0.5359.71)

status 429 and 500

Status code 429: {"detail":"Too many requests, please slow down"}
Status code 500: {"detail":"Hmm...something seems to have gone wrong. Maybe try me again in a little bit."}

Hi, I want to use ChatGPT to generate at least 1000 sentences, but I met the 429 and 500 problem, could you please add some code to deal with it?

Suggestion, Not error

When the package is run, it opens a chat.openai.com/auth/session link. Instead of specifying a session token, why not grab it from that json response? The session token is labelled "acces_token" in the json.

403 error, I suspect OpenAI have implemented some barrier?

My code used to run just fine, but now I'm getting a 403 error all the time. What could be the issue?

def chatGPT_response(prompt):

session_token = "valide token"
api = ChatGPT(session_token)
print(prompt)

resp = api.send_message(prompt)
response = resp['message']

print(response)
return response

No such file or directory: 'Xvfb'

Hi Terry,
thanks for all the work on this.

I am trying to call the API from google colab but continue to receive the following error when running on Windows 10 or in ubuntu [gui is xfce4] I continue to receive the following error even though I have xvfb installed.
[xvfb is already the newest version (2:1.20.13-1ubuntu1~20.04.4).]

api = ChatGPT(session_token)

FileNotFoundError Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/pyChatGPT/pyChatGPT.py in __get_cf_cookies(self, retry)
95 try:
---> 96 display = Display()
97 except FileNotFoundError as e:

9 frames
FileNotFoundError: [Errno 2] No such file or directory: 'Xvfb'

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/pyChatGPT/pyChatGPT.py in __get_cf_cookies(self, retry)
97 except FileNotFoundError as e:
98 if 'No such file or directory: 'Xvfb'' in str(e):
---> 99 raise ValueError(
100 'Headless machine detected. Please install Xvfb to start a virtual display: sudo apt install xvfb'
101 )

ValueError: Headless machine detected. Please install Xvfb to start a virtual display: sudo apt install xvfb

Thanks in advance,
Dennis

how can i solve this problem?

`
token = ""

api = ChatGPT(session_token=token)
response = api.send_message("naber")
print(response["message"])
`

error :
if not 0 <= time_low < 1<<32L:

Response (send_message) not giving back results and throwing error

def chatgpt_api_request(api, movie):
    response = api.send_message("Give me a 200 word movie plot line description of the Bollywood movie " + movie + " without character names in it and do not start with the movie title")
    print(response)
    return response["message"]
for idx in plots_list_df.index:
    movie = plots_list_df.iloc[idx, 0]
    response = chatgpt_api_request(api, movie)
    print(response)
    plots_list_df.iloc[idx, 1] = response
    
plots_list_df

The response is not getting back...

ERROR -
IndexError Traceback (most recent call last)
in
1 for idx in plots_list_df.index:
2 movie = plots_list_df.iloc[idx, 0]
----> 3 response = chatgpt_api_request(api, movie)
4 print(response)
5 plots_list_df.iloc[idx, 1] = response

in chatgpt_api_request(api, movie)
1 def chatgpt_api_request(api, movie):
----> 2 response = api.send_message("Give me a 200 word movie plot line description of the Bollywood movie " + movie + " without character names in it and do not start with the movie title")
3 print(response)
4 return response["message"]

~\anaconda3\lib\site-packages\pyChatGPT\pyChatGPT.py in send_message(self, message)
393 # Get the response element
394 self.__verbose_print('[send_msg] Finding response element')
--> 395 response = self.driver.find_elements(
396 By.XPATH, "//div[starts-with(@Class, 'markdown prose break-words')]"
397 )[-1]

IndexError: list index out of range
ChatGPT Movie.zip

Can we use beautiful supe instade of selenium

to send a request every time it's bringing the browser that can't be good.

if there is now API on the list there can be a proper request-sending situation.

Its bring Browser.
image

and There is x path problem too.
image

</textarea> is not clickable

Traceback (most recent call last):
  File "/home/sunao/sqa/models/run_gpt3.py", line 260, in <module>
    prediction, output = get_gpt3_result(prompt, args)  # 'A', ..., 'E'
  File "/home/sunao/sqa/models/run_gpt3.py", line 73, in get_gpt3_result
    res = response.send_message(prompt)
  File "/home/sunao/anaconda3/envs/sqa/lib/python3.10/site-packages/pyChatGPT/pyChatGPT.py", line 341, in send_message
    textbox.click()
  File "/home/sunao/anaconda3/envs/sqa/lib/python3.10/site-packages/selenium/webdriver/remote/webelement.py", line 93, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/home/sunao/anaconda3/envs/sqa/lib/python3.10/site-packages/selenium/webdriver/remote/webelement.py", line 410, in _execute
    return self._parent.execute(command, params)
  File "/home/sunao/anaconda3/envs/sqa/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 444, in execute
    self.error_handler.check_response(response)
  File "/home/sunao/anaconda3/envs/sqa/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 249, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <textarea tabindex="0" data-id="root" style="max-height: 200px; height: 24px; overflow-y: hidden;" rows="1" placeholder="" class="m-0 w-full resize-none border-0 bg-transparent p-0 pr-7 focus:ring-0 focus-visible:ring-0 dark:bg-transparent"></textarea> is not clickable at point (528, 418). Other element would receive the click: <div class="flex gap-4 mt-6">...</div>
  (Session info: chrome=108.0.5359.71)
Stacktrace:
#0 0x56143354d2a3 <unknown>
#1 0x56143330bf77 <unknown>
#2 0x56143334f0a9 <unknown>
#3 0x56143334d18d <unknown>
#4 0x56143334ad88 <unknown>
#5 0x561433349f2d <unknown>
#6 0x56143333ddc5 <unknown>
#7 0x561433368b32 <unknown>
#8 0x56143333d61f <unknown>
#9 0x561433368cfe <unknown>
#10 0x56143338047c <unknown>
#11 0x561433368903 <unknown>
#12 0x56143333bece <unknown>
#13 0x56143333cfde <unknown>
#14 0x56143359d63e <unknown>
#15 0x5614335a0b79 <unknown>
#16 0x56143358389e <unknown>
#17 0x5614335a1a83 <unknown>
#18 0x561433576505 <unknown>
#19 0x5614335c2ca8 <unknown>
#20 0x5614335c2e36 <unknown>
#21 0x5614335de333 <unknown>
#22 0x7f7d575a36db start_thread

the indexerror was fixed, but still got an unexpected error. it looks like that the focus was on a textarea and clicked

Cloudflare challenge failed

raise ValueError(f'Cloudflare challenge failed: {self.driver.page_source}')
ValueError: Cloudflare challenge failed:
<title>Just a moment...</title>




Too many requests

Hello!

I just type into two questions, one after another and it says "To many requests in one hour, Try again later". But I just try one problem!

Could you help me solve this problem?

Thanks,

api1.reset_conversation() crashes de app

Hi dear I'm [fighting] with this library to be able to connect me to chatgpt.
The example code works in my case without api1.reset_conversation() but this only works
one time in the second time when I send another question to chatgpt the app crashes.

I'm testing it by using ubuntu


Traceback (most recent call last):
  File "/home/freddy/Documents/aws-projects/chatgptproject/process.py", line 155, in <module>
    mqttClient.loop_forever()
  File "/usr/local/lib/python3.10/dist-packages/paho/mqtt/client.py", line 1756, in loop_forever
    rc = self._loop(timeout)
  File "/usr/local/lib/python3.10/dist-packages/paho/mqtt/client.py", line 1164, in _loop
    rc = self.loop_read()
  File "/usr/local/lib/python3.10/dist-packages/paho/mqtt/client.py", line 1556, in loop_read
    rc = self._packet_read()
  File "/usr/local/lib/python3.10/dist-packages/paho/mqtt/client.py", line 2439, in _packet_read
    rc = self._packet_handle()
  File "/usr/local/lib/python3.10/dist-packages/paho/mqtt/client.py", line 3033, in _packet_handle
    return self._handle_publish()
  File "/usr/local/lib/python3.10/dist-packages/paho/mqtt/client.py", line 3327, in _handle_publish
    self._handle_on_message(message)
  File "/usr/local/lib/python3.10/dist-packages/paho/mqtt/client.py", line 3570, in _handle_on_message
    on_message(self, self._userdata, message)
  File "/home/freddy/Documents/aws-projects/chatgptproject/process.py", line 148, in on_message
    transcribe_file(JOB_NAME, file_uri, transcribe_client)
  File "/home/freddy/Documents/aws-projects/chatgptproject/process.py", line 82, in transcribe_file
    sendToChatGPT(text)
  File "/home/freddy/Documents/aws-projects/chatgptproject/process.py", line 115, in sendToChatGPT
    api1.reset_conversation()  # reset the conversation - Se comenta por que genera crashes.
  File "/usr/local/lib/python3.10/dist-packages/pyChatGPT/pyChatGPT.py", line 416, in reset_conversation
    self.driver.find_element(By.LINK_TEXT, 'New Thread').click()
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 861, in find_element
    return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 444, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/errorhandler.py", line 249, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"New Thread"}
  (Session info: chrome=108.0.5359.98)
Stacktrace:
#0 0x563bb34472a3 <unknown>
#1 0x563bb3205f77 <unknown>
#2 0x563bb324280c <unknown>
#3 0x563bb3242a71 <unknown>
#4 0x563bb327c734 <unknown>
#5 0x563bb3262b5d <unknown>
#6 0x563bb327a47c <unknown>
#7 0x563bb3262903 <unknown>
#8 0x563bb3235ece <unknown>
#9 0x563bb3236fde <unknown>
#10 0x563bb349763e <unknown>
#11 0x563bb349ab79 <unknown>
#12 0x563bb347d89e <unknown>
#13 0x563bb349ba83 <unknown>
#14 0x563bb3470505 <unknown>
#15 0x563bb34bcca8 <unknown>
#16 0x563bb34bce36 <unknown>
#17 0x563bb34d8333 <unknown>
#18 0x7f6845670b43 <unknown>

I repeat my code only works one time commeting this line of code api1.reset_conversation() . If I uncoment it the application will get crash.

I hope a sooner solution.
thanks.

Changes to ChatGPT web site causing pyChatGPT to no longer work?

Hi,

Thanks for this incredible project :) I used it as recently as earlier today but it seems that something has changed in the page layout and pyChatGPT bails with:

Traceback (most recent call last):
  File "C:\Users\Bart\anaconda3\envs\chatgpt\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\Bart\anaconda3\envs\chatgpt\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\projects\ChatGPT\chatgpt.py", line 183, in <module>
    loop.run_until_complete(asyncio.gather(*tasks))
  File "C:\Users\Bart\anaconda3\envs\chatgpt\lib\asyncio\base_events.py", line 649, in run_until_complete
    return future.result()
  File "C:\projects\ChatGPT\chatgpt.py", line 40, in run
    self._chat_gpt.reset_conversation()
  File "C:\Users\Bart\anaconda3\envs\chatgpt\lib\site-packages\pyChatGPT\pyChatGPT.py", line 418, in reset_conversation
    self.driver.find_element(By.LINK_TEXT, 'New Chat').click()
  File "C:\Users\Bart\anaconda3\envs\chatgpt\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 861, in find_element
    return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
  File "C:\Users\Bart\anaconda3\envs\chatgpt\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 444, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Bart\anaconda3\envs\chatgpt\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"New Chat"}

Has anyone else encountered this? I am using the session token API.

Thank you,

Bart

Chrome tab is staying open

Was working pretty well for a while, but started to get an error with it only taking one message before saying i was sending too many requests per hour as an error. Realized there was a new version available and assuming it was just openai patching a previous use, so updated to latest version, and now it seems to work fine but the chrome browser tab ChatGPT(TOKEN) uses is staying open on my screen instead of running in the background. Is this new behavior intentional?

Feature Request: Optional Moderation

Can an option be added to the constructor to block moderation requests:

chatgpt_instance.driver.execute_cdp_cmd(
    "Network.setBlockedURLs", {"urls": ["https://chat.openai.com/backend-api/moderations"]}
)

session deleted because of page crash

I run on linux and install chromium-browser and xvfb, but there is an error:

Traceback (most recent call last):
  File "1.py", line 7, in <module>
    resp = api1.send_message('hello')
  File "/usr/local/lib/python3.8/site-packages/pyChatGPT/pyChatGPT.py", line 151, in send_message
    self.__ensure_cf()
  File "/usr/local/lib/python3.8/site-packages/pyChatGPT/pyChatGPT.py", line 113, in __ensure_cf
    self.driver.switch_to.new_window('tab')
  File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/switch_to.py", line 108, in new_window
    value = self._driver.execute(Command.NEW_WINDOW, {"type": type_hint})["value"]
  File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 444, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 249, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: session deleted because of page crash
from unknown error: cannot determine loading status
from tab crashed
  (Session info: chrome=108.0.5359.94)
Stacktrace:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.