Skip to content
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

Added custom appID insertion to be added on requests to help developers #8

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/capsolver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

api_base = os.environ.get("CAPSOLVER_API_BASE", "https://api.capsolver.com")
api_key = os.environ.get("CAPSOLVER_API_KEY")
appId = os.environ.get("CAPSOLVER_APP_ID")
solve = Capsolver.solve
balance = Capsolver.balance
proxy = None
Expand All @@ -25,5 +26,6 @@

"api_base",
"api_key",
"appId",
"proxy",
]
7 changes: 5 additions & 2 deletions src/capsolver/api_requestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ def _make_session():


class APIRequestor:
def __init__(self, key=None, api_base=None):
def __init__(self, key=None, api_base=None, appId=None):
self.api_base = api_base or capsolver.api_base
self.api_key = key or capsolver.api_key
self.appId = appId or capsolver.appId

def request(self, method, url, params=None, headers=None, request_timeout=None):
result = self.request_raw(method.lower(), url, params=params, supplied_headers=headers, request_timeout=request_timeout)
Expand Down Expand Up @@ -113,8 +114,10 @@ def request_raw(self, method, url, *, params=None, supplied_headers=None, reques
abs_url = "%s%s" % (self.api_base, url)
headers = self._validate_headers(supplied_headers)
json_data = {
"clientKey":self.api_key,
"clientKey":self.api_key
}
if self.appId:
json_data["appId"] = self.appId
json_data.update(params)
headers = self.request_headers(headers)
if not hasattr(_thread_context, "session"):
Expand Down