PyChatGPT icon indicating copy to clipboard operation
PyChatGPT copied to clipboard

A Function to respond to CAPTCHA verification

Open sweetbrulee opened this issue 2 years ago • 2 comments

Hey, is it possible to make a function to respond to CAPTCHA image result (__part_five in openai.py), instead of using input on the console?

sweetbrulee avatar Dec 08 '22 16:12 sweetbrulee

do you mean a function to perform the CAPTCHA verification or a better log to the console?

buabaj avatar Dec 08 '22 16:12 buabaj

do you mean a function to perform the CAPTCHA verification or a better log to the console?

The current CAPTCHA checking strategy stores the verification code image locally and waits for the user to recognize and input the code to the console.

I thought it's good to add a function to do this, to provide an alternative.

for example, if the CAPTCHA image hint to enter 'e8A6M', then I could just use the function to respond: respond_func('e8A6M') instead of typing 'e8A6M' in console.

sweetbrulee avatar Dec 08 '22 17:12 sweetbrulee

you cannot call a function like respond_func('e8A6M') a when the program is already running. This would need a service like RabbitMQ/ActiveMQ

rawandahmad698 avatar Dec 08 '22 19:12 rawandahmad698

TL;DR: allow us to pass a captcha solver method and store the authentication information to a file to keep track of it between different runs.

My suggested solution:

  1. Add a captcha_solver parameter to the Options object that receives a method to be used to solve captchas
  2. At line 254 in src/pychatgpt/classes/openai.py add a check: if captcha_solver: where the method is called with the result of reportlab.graphics.renderPM.drawToPIL
  3. The method does whatever it wants with the Pillow object and returns the string
  4. Continue execution using the captcha solution obtained programmatically

One problem I see with solving captchas programmatically is that it can take quite some time (some APIs can take up to 20s to reply) and as such if you have no way to await the method, you would have to either sleep for an unknown amount of time or use a clunky while loop that checks if the output is available.

I think that the current authentication implementation is heavily biased towards interactive use, which is totally fine but makes devs lives a bit less colorful. Maybe consider:

  1. Either make all the necessary information like CSRF token (if it doesn't change every request), Current State and Access Token easily available so developers can tuck it somewhere and write their own logic to renew authentication, or;
  2. Pickle that information to a file that the library can use to track how the relevant information has changed between multiple sessions.

EDIT:

you cannot call a function like respond_func('e8A6M') a when the program is already running. This would need a service like RabbitMQ/ActiveMQ

This should be plenty possible by just awaiting on it whenever you need to solve captchas, if that ever happens during execution. It would block? Yes. But in this case you want it to block as the information is required to continue execution. Okay, you would need this to be rewritten asynchronously, but sleeping/checking for it in a while loop should be enough I guess.

alexandreteles avatar Dec 08 '22 19:12 alexandreteles