bilalahmed381 opened a new issue, #30697:
URL: https://github.com/apache/airflow/issues/30697
### What do you see as an issue?
**Environment:**
- OS (e.g. from /etc/os-release): SUSE Linux Enterprise Server 15 SP4
- Kernel (e.g. uname -a): Linux 5.14.21-150400.24.46-default
- Install tools: pip
- Airflow: 2.5.1
- Python: 3.10.10
- apache-airflow-providers-http: 4.1.1
**Issue:**
I'm using airflow httphook to get authentication token. But I'm facing bad
request error, status response 400. I verified the payload and header is
correct. If I use ```requests.post("https://login.cac1.pure.cloud/oauth/token",
headers=request_headers, data=request_body)``` response status is 200. However,
on using ```response: requests.Response =
HttpHook(http_conn_id="genesys_login",
method="POST").run(endpoint="/oauth/token", headers=request_headers,
data=request_body)``` it gives bad response error. Then I upgraded to
`apache-airflow-providers-http==4.3.0` still issue is persistent.
**Request Payload and Header:**
```
authorization = base64.b64encode(bytes(<client_id> + ":" + <client_secret>,
"ISO-8859-1")).decode("ascii")
request_headers = {
"Authorization": f"Basic {authorization}",
"Content-Type": "application/x-www-form-urlencoded",
}
request_body = {"grant_type": "client_credentials"}
```
**Connection:**
<img width="887" alt="Screenshot 2023-04-17 at 11 30 06 PM"
src="https://user-images.githubusercontent.com/30565416/232663921-bdb1b10d-35eb-41a3-99fe-609a8abfa37d.png">
Kindly find the error log below.
```
[2023-04-17, 14:42:03 MST] {taskinstance.py:1280} INFO - Starting attempt 1
of 1
[2023-04-17, 14:42:03 MST] {taskinstance.py:1281} INFO -
--------------------------------------------------------------------------------
[2023-04-17, 14:42:03 MST] {taskinstance.py:1300} INFO - Executing
<Task(_PythonDecoratedOperator): token_validation.update_token> on 2023-04-17
21:41:56.901593+00:00
[2023-04-17, 14:42:03 MST] {standard_task_runner.py:55} INFO - Started
process 13621 to run task
[2023-04-17, 14:42:03 MST] {standard_task_runner.py:82} INFO - Running:
['airflow', 'tasks', 'run', 'monitor_email', 'token_validation.update_token',
'manual__2023-04-17T21:41:56.901593+00:00', '--job-id', '21422', '--raw',
'--subdir', 'DAGS_FOLDER/genesys_integration.py', '--cfg-path',
'/tmp/tmpqa3air9p']
[2023-04-17, 14:42:03 MST] {standard_task_runner.py:83} INFO - Job 21422:
Subtask token_validation.update_token
[2023-04-17, 14:42:03 MST] {task_command.py:388} INFO - Running
<TaskInstance: monitor_email.token_validation.update_token
manual__2023-04-17T21:41:56.901593+00:00 [running]> on host lxapp-cp-jup15
[2023-04-17, 14:42:03 MST] {logging_mixin.py:137} WARNING -
/home/e92215/miniforge3/envs/airflow/lib/python3.10/site-packages/airflow/models/renderedtifields.py:238
RemovedIn20Warning: ORDER BY columns added implicitly due to DISTINCT is
deprecated and will be removed in SQLAlchemy 2.0. SELECT statements with
DISTINCT should be written to explicitly include the appropriate columns in the
columns clause (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
[2023-04-17, 14:42:03 MST] {taskinstance.py:1507} INFO - Exporting the
following env vars:
AIRFLOW_CTX_DAG_OWNER=airflow
AIRFLOW_CTX_DAG_ID=monitor_email
AIRFLOW_CTX_TASK_ID=token_validation.update_token
AIRFLOW_CTX_EXECUTION_DATE=2023-04-17T21:41:56.901593+00:00
AIRFLOW_CTX_TRY_NUMBER=1
AIRFLOW_CTX_DAG_RUN_ID=manual__2023-04-17T21:41:56.901593+00:00
[2023-04-17, 14:42:03 MST] {genesys_token_validate.py:138} INFO - Validating
token with HTTP request
[2023-04-17, 14:42:03 MST] {base.py:73} INFO - Using connection ID
'genesys_login' for task execution.
[2023-04-17, 14:42:04 MST] {http.py:163} ERROR - HTTP error: Bad Request
[2023-04-17, 14:42:04 MST] {http.py:164} ERROR -
{"error":"invalid_client","description":"client not
found","error_description":"client not found"}
[2023-04-17, 14:42:04 MST] {taskinstance.py:1768} ERROR - Task failed with
exception
Traceback (most recent call last):
File
"/home/e92215/miniforge3/envs/airflow/lib/python3.10/site-packages/airflow/providers/http/hooks/http.py",
line 161, in check_response
response.raise_for_status()
File
"/home/e92215/miniforge3/envs/airflow/lib/python3.10/site-packages/requests/models.py",
line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url:
https://login.cac1.pure.cloud/oauth/token
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File
"/home/e92215/miniforge3/envs/airflow/lib/python3.10/site-packages/airflow/decorators/base.py",
line 217, in execute
return_value = super().execute(context)
File
"/home/e92215/miniforge3/envs/airflow/lib/python3.10/site-packages/airflow/operators/python.py",
line 175, in execute
return_value = self.execute_callable()
File
"/home/e92215/miniforge3/envs/airflow/lib/python3.10/site-packages/airflow/operators/python.py",
line 192, in execute_callable
return self.python_callable(*self.op_args, **self.op_kwargs)
File "/home/e92215/airflow/dags/authentication/genesys_token_validate.py",
line 140, in update_token
response: requests.Response = HttpHook(http_conn_id="genesys_login",
method="POST").run(
File
"/home/e92215/miniforge3/envs/airflow/lib/python3.10/site-packages/airflow/providers/http/hooks/http.py",
line 151, in run
return self.run_and_check(session, prepped_request, extra_options)
File
"/home/e92215/miniforge3/envs/airflow/lib/python3.10/site-packages/airflow/providers/http/hooks/http.py",
line 204, in run_and_check
self.check_response(response)
File
"/home/e92215/miniforge3/envs/airflow/lib/python3.10/site-packages/airflow/providers/http/hooks/http.py",
line 165, in check_response
raise AirflowException(str(response.status_code) + ":" + response.reason)
airflow.exceptions.AirflowException: 400:Bad Request
[2023-04-17, 14:42:04 MST] {taskinstance.py:1318} INFO - Marking task as
FAILED. dag_id=monitor_email, task_id=token_validation.update_token,
execution_date=20230417T214156, start_date=20230417T214203,
end_date=20230417T214204
[2023-04-17, 14:42:04 MST] {standard_task_runner.py:100} ERROR - Failed to
execute job 21422 for task token_validation.update_token (400:Bad Request;
13621)
[2023-04-17, 14:42:04 MST] {local_task_job.py:208} INFO - Task exited with
return code 1
[2023-04-17, 14:42:04 MST] {taskinstance.py:2578} INFO - 0 downstream tasks
scheduled from follow-on schedule check
```
### Solving the problem
No Clue
### Anything else
I also used VS Code Thunder client to test the endpoint and it works fine
with status code 200.
### Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]