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

Send requests through socks proxy in create-project-async. #18

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions create-project-async/api_client.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@


def create_project(base_url, client_id, client_secret, team_id, documents_path="documents"):
print("Creating project...")
try:
Project.create(
base_url,
2 changes: 1 addition & 1 deletion create-project-async/project_configuration.json
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
"splitDocumentOption": null,
"projectSettings": {
"enableEditLabelSet": true,
"enableEditSentence": true,
"enableEditSentence": false,
"hideLabelerNamesDuringReview": false,
"hideRejectedLabelsDuringReview": true,
"hideLabelsFromInactiveLabelSetDuringReview": false,
4 changes: 3 additions & 1 deletion create-project-async/src/helper.py
Original file line number Diff line number Diff line change
@@ -6,8 +6,10 @@
def get_access_token(base_url, client_id, client_secret):
client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client)
oauth.proxies = {'all': 'socks5://127.0.0.1:8900'}
print("fetching access token...")
token = oauth.fetch_token(token_url=base_url + '/api/oauth/token',
client_id=client_id, client_secret=client_secret)
client_id=client_id, client_secret=client_secret, verify=False)
return token['access_token']


5 changes: 3 additions & 2 deletions create-project-async/src/job.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import requests
import json
import time
from src.helper import get_access_token, get_operations
from .helper import get_access_token, get_operations

CHECK_JOB_INTERVAL_SECONDS = 5

@@ -15,8 +15,9 @@ def get_status(base_url, client_id, client_secret, job_id, operations_path):
operations["variables"]["input"] = job_id
data = json.dumps(operations)
headers = {'Authorization': 'Bearer ' + access_token, 'Content-Type': 'application/json'}
proxies = {'all': 'socks5://127.0.0.1:8900'}
while True:
response = requests.request("POST", url, headers=headers, data=data)
response = requests.request("POST", url, headers=headers, data=data, proxies=proxies, verify=False)
if response.status_code != 200 or not ('json' in response.headers['content-type']):
print(response.text.encode('utf8'))
return
9 changes: 6 additions & 3 deletions create-project-async/src/project.py
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@
import os

import requests
from src.exceptions.invalid_options import InvalidOptions
from src.helper import get_access_token, get_operations
from .exceptions import invalid_options as InvalidOptions
from .helper import get_access_token, get_operations


EXTERNAL_OBJECT_STORAGE_FILE_KEY = "externalObjectStorageFileKey"
@@ -66,6 +66,8 @@ def create(

headers = {"Authorization": "Bearer " + access_token}
data = {"operations": json.dumps(operations), "map": json.dumps(payload_map)}
print(f"requesting url {url}...")
print(f" with headers {headers}...")
response = Project.__call_graphql(
url=url, headers=headers, data=data, files=files
)
@@ -140,7 +142,8 @@ def __handle_document_list(

@staticmethod
def __call_graphql(url: str, headers: dict, data: dict, files=None):
return requests.request("POST", url, headers=headers, data=data, files=files)
proxies = {'all': 'socks5://127.0.0.1:8900'}
return requests.request("POST", url, headers=headers, data=data, files=files, verify=False, proxies=proxies)

@staticmethod
def __process_graphql_response(response, base_url, client_id, client_secret):
1 change: 1 addition & 0 deletions create-project-async/src/requirements.txt
Original file line number Diff line number Diff line change
@@ -3,3 +3,4 @@ requests_oauthlib==1.3.0
oauthlib==3.1.0
python-dotenv
fire
PySocks