Skip to content

Commit

Permalink
fix: add decoding json to avoid sending special encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdellahitech committed Dec 28, 2023
1 parent ba33dec commit f630731
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/hrflow_connectors/connectors/talentsoft/warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,15 @@ class WriteProfileParameters(ParametersModel):
field_type=FieldType.Auth,
)


def decode_unicode(input_str):
try:
return bytes(input_str, "utf-8").decode("unicode_escape")
except UnicodeDecodeError as e:
print(f"Error decoding Unicode: {e}")
return input_str


def decode_json(obj):
if isinstance(obj, str):
return decode_unicode(obj)
Expand All @@ -174,9 +176,14 @@ def decode_json(obj):
return {key: decode_json(value) for key, value in obj.items()}
else:
return obj



def get_talentsoft_auth_token(
client_url: str, client_id: str, client_secret: str, scope: str = TOKEN_SCOPE,front_or_back="back"
client_url: str,
client_id: str,
client_secret: str,
scope: str = TOKEN_SCOPE,
front_or_back="back",
) -> str:
if front_or_back == "front":
data = dict(
Expand Down Expand Up @@ -210,6 +217,7 @@ def get_talentsoft_auth_token(
"Failed to get token from response with error={}".format(repr(e))
)


def post_applicant_front(client_url, token, applicant, files, job_reference=None):
pdb.set_trace()
if job_reference:
Expand Down Expand Up @@ -389,6 +397,7 @@ def write_profiles(
if parameters.job_reference:
profile["application"]["offerReference"] = parameters.job_reference
profile_ts = dict(applicantApplication=json.dumps(profile))
profile_ts = decode_json(profile_ts)
try:
response = post_applicant_front(
parameters.client_url,
Expand All @@ -398,7 +407,11 @@ def write_profiles(
parameters.job_reference,
)
except Exception as e:
adapter.error("Failed to write profile with error={}, and response={}".format(e, response))
adapter.error(
"Failed to write profile with error={}, and response={}".format(
e, response
)
)
failed_profiles.append(profile)

return failed_profiles
Expand Down

0 comments on commit f630731

Please sign in to comment.