Skip to content

Optimised imports - api.py #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions twocaptcha/api.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/usr/bin/env python3

import requests

from requests import get, post, RequestException

class NetworkException(Exception):
pass


class ApiException(Exception):
pass

Expand Down Expand Up @@ -47,7 +45,7 @@ def in_(self, files={}, **kwargs):
if files:

files = {key: open(path, 'rb') for key, path in files.items()}
resp = requests.post(current_url,
resp = post(current_url,
data=kwargs,
files=files)

Expand All @@ -56,15 +54,15 @@ def in_(self, files={}, **kwargs):
elif 'file' in kwargs:

with open(kwargs.pop('file'), 'rb') as f:
resp = requests.post(current_url,
resp = post(current_url,
data=kwargs,
files={'file': f})

else:
resp = requests.post(current_url,
resp = post(current_url,
data=kwargs)

except requests.RequestException as e:
except RequestException as e:
raise NetworkException(e)

if resp.status_code != 200:
Expand Down Expand Up @@ -102,7 +100,7 @@ def res(self, **kwargs):

try:
current_url_out = 'https://'+self.post_url+'/res.php'
resp = requests.get(current_url_out, params=kwargs)
resp = get(current_url_out, params=kwargs)

if resp.status_code != 200:
raise NetworkException(f'bad response: {resp.status_code}')
Expand All @@ -112,7 +110,7 @@ def res(self, **kwargs):
if 'ERROR' in resp:
raise ApiException(resp)

except requests.RequestException as e:
except RequestException as e:
raise NetworkException(e)

return resp