Im trying to do an API call to my Django app throws 403 when run inside github actions but works well in local or any machine.
please find below scripts and logs
my yaml in .github/worflows/ci_job.yml
`on:
pull_request:
types:
– opened
– reopened
– synchronize
– ready_for_review
push:
branches:
– ‘!main’
env:
AUTH_TOKEN: ${{ secrets.AUTH_TOKEN }}
jobs:
api_call:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10.11'
- name: Install dependencies
run: pip install requests
- name: Run Python script
run: python post_request.py`
my python script
`import requests
import os
auth_token = os.environ[“AUTH_TOKEN”]
url = “https://app-low-demo.superor.com/api/job/”
headers = {
‘accept’: ‘application/json’,
‘Authorization’: f’Token {auth_token}’,
‘Content-Type’: ‘application/json’
}
print(“headers”,headers)
response = requests.get(url, headers=headers)
if response.status_code == 200:
print(“Success:”, response.json())
else:
print(“Failed:”, response.status_code, response.text)`
Log in github actions:
Run python post_request.py headers {'accept': 'application/json', 'Authorization': 'Token ***', 'Content-Type': 'application/json'} Failed: 403 <!DOCTYPE html><html lang="en-US"><head><title>Just a moment...</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=Edge"><meta name="robots" content="noindex,nofollow"><meta name="viewport" content="width=device-width,initial-scale=1"><style>*{box-sizing:border-box;margin:0;padding:0}html{line-height:1.15;-webkit-text-size-adjust:100%;color:#313131}button,html{font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji}@media (prefers-color-scheme:dark){body{background-color:#222;color:#d9d9d9}body a{color:#fff}body a:hover{color:#ee730a;text-decoration:underline}body .lds-ring div{border-color:#999 transparent transparent}body .font-red{color:#b20f03}body .pow-button{background-color:#4693ff;color:#1d1d1d}body #challenge-success-text{background-image:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy5
But When i actually run the same python file in local with hardcoded token value it works well i get the repspnse 200 and i get the actual response
Vriddhachalam S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.