Skip to content

Commit 83ec555

Browse files
author
2captcha
authored
Merge pull request #18 from caffeinatedMike/master
Added ability to supply image url to normal captcha method
2 parents d00edac + b3bdb66 commit 83ec555

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ Below you can find basic examples for every captcha type. Check out [examples di
9090
To bypass a normal captcha (distorted text on image) use the following method. This method also can be used to recognize any text on the image.
9191
```python
9292
result = solver.normal('path/to/captcha.jpg', param1=..., ...)
93+
# OR
94+
result = solver.normal('https://site-with-captcha.com/path/to/captcha.jpg', param1=..., ...)
9395
```
9496

9597
### Text Captcha

twocaptcha/solver.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os, sys
44
import time
5+
import requests
56

67
try:
78
from .api import ApiClient
@@ -55,7 +56,7 @@ def normal(self, file, **kwargs):
5556
Wrapper for solving normal captcha (image)
5657
5758
Required:
58-
file (image or base64)
59+
file (image, base64, or url)
5960
6061
Optional params:
6162
@@ -432,6 +433,12 @@ def get_method(self, file):
432433

433434
if not '.' in file and len(file) > 50:
434435
return {'method': 'base64', 'body': file}
436+
437+
if file.startswith('http'):
438+
img_resp = requests.get(file)
439+
if img_resp.status_code != 200:
440+
raise ValidationException(f'File could not be downloaded from url: {file}')
441+
return {'method': 'base64', 'body': b64encode(img_resp.content).decode('utf-8')}
435442

436443
if not os.path.exists(file):
437444
raise ValidationException(f'File not found: {file}')

0 commit comments

Comments
 (0)