I am trying to solve normal captcha using 2Captcha python API, but it gives error that file could not be downloaded. I dont know why is this happening, as I can download it manually from browser and do save as .png to download it. The below is the code
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
from twocaptcha import TwoCaptcha
solver = TwoCaptcha(apikey)
try:
result = solver.normal('https://v2.gcchmc.org/captcha/image/aa699f305917812978c911e87ab126a782f726e7/')
except Exception as e:
sys.exit(e)
else:
sys.exit('solved: ' + str(result))
I also tried to download the file using requests and then give it to the API but that also shows error. The code for requests is
url = 'https://v2.gcchmc.org/captcha/image/aa699f305917812978c911e87ab126a782f726e7/'
import requests
from PIL import Image
from io import BytesIO
response = requests.get(url)
img = Image.open(BytesIO(response.content)) # error occurs here
img.save('output.png')
The Error is
raise UnidentifiedImageError(
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x00000141224AB2C0>
If anyone can help me download the image using script I will be thankful. The captcha is showed on the following url: https://v2.gcchmc.org/book-appointment/