jobsuche-api
jobsuche-api copied to clipboard
Python client sample funktioniert nicht
Siehe bitte Code-Kommentare ganz oben und bei den Requests.
# Started from sample https://github.com/bundesAPI/jobsuche-api/blob/main/python-client/README.md
# Added OAuth code according to https://github.com/bundesAPI/jobsuche-api/blob/main/README.md
# Tried different API methods -- see below
import time
import requests
from deutschland import jobsuche
from pprint import pprint
from deutschland.jobsuche.api import default_api
from deutschland.jobsuche.model.job_application_details import JobApplicationDetails
from deutschland.jobsuche.model.job_details import JobDetails
from deutschland.jobsuche.model.job_search_response import JobSearchResponse
# Defining the host is optional and defaults to https://rest.arbeitsagentur.de/jobboerse/jobsuche-service
# See configuration.py for a list of all supported configuration parameters.
configuration = jobsuche.Configuration(
host = "https://rest.arbeitsagentur.de/jobboerse/jobsuche-service"
)
def get_access_token():
global access_token
"""
Access Token: Get the new access token
params : client_id,
client_secret,
grant_type,
"""
headers = {
'Host': 'rest.arbeitsagentur.de',
'Accept': '*/*',
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
'Accept-Language': 'en-us',
'User-Agent': 'Jobsuche/1070 CFNetwork/1220.1 Darwin/20.3.0',
}
data = {
'client_id': 'c003a37f-024f-462a-b36d-b001be4cd24a',
'client_secret': '32a39620-32b3-4307-9aa1-511e3d7f48a8',
'grant_type': 'client_credentials'
}
response = requests.post('https://rest.arbeitsagentur.de/oauth/gettoken_cc', headers=headers, data=data)
response = response.json()
access_token = response['access_token']
print(access_token)
return access_token
access_token = get_access_token()
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.
# Configure OAuth2 access token for authorization: clientCredAuth
configuration = jobsuche.Configuration(
host = "https://rest.arbeitsagentur.de/jobboerse/jobsuche-service"
)
configuration.access_token = access_token
# Enter a context with an instance of the API client
with jobsuche.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = default_api.DefaultApi(api_client)
hash_id = "jEZXQszSIsGz582sLJQA5owhlXnKh34ln1pFdFHJ_0I=" # str |
try:
# Unternehmen Logo -- THIS WAS PART OF ORIGINAL SAMPLE CODE
# Throws with 404
# api_response = api_instance.ed_v1_arbeitgeberlogo_hash_id_get(hash_id)
# pprint(api_response)
# Bewerber -- ADDED FOR TESTING
# Apparently published API version (installed via PIP) doesn't feature the method.
# I am getting this:
# AttributeError: 'DefaultApi' object has no attribute 'pc_v2_app_jobs_hash_id_bewerbung_get'
# api_response = api_instance.pc_v2_app_jobs_hash_id_bewerbung_get(hash_id)
# pprint(api_response)
# Job details -- ADDED FOR TESTING
# Same problem as with pc_v2_app_jobs_hash_id_bewerbung_get
api_response = api_instance.pc_v2_jobdetails_hash_id_get(hash_id)
pprint(api_response)
except jobsuche.ApiException as e:
print("Exception when calling DefaultApi->ed_v1_arbeitgeberlogo_hash_id_get: %s\n" % e)
Which error do you get?
I see, the error are within the code. Will look into this.