Forum Discussion

naveen_raam's avatar
naveen_raam
Contributor
4 years ago

Bulk API request using python failing

I have tried both the examples recommended for python and both are failing with different errors.

 

 

access_token = "<my api token>" # Place the "Bulk API access token" from Community Analytics here
client_id = "my client id" # Place the "Client ID" from Community Analytics here
response = requests.get(
'https://api.lithium.com/lsi-data/v1/data/export/community/communityid',
params={'fromDate': '20210630', # Set the start date in YYYYMMDD format
'toDate': '20210707'}, # Set the end date in YYYYMMDD format
auth=(access_token, ''),
headers={'client-id': client_id,
'Accept': 'application/json' }
data = response.json() 
print(data)

 

 

 

Output:

 

SSLError: HTTPSConnectionPool(host='api.lithium.com', port=443): Max retries exceeded with url: /lsi-data/v1/data/export/community/communityid?fromDate=20210630&toDate=20210707 (Caused by SSLError(SSLError(9, '[X509] PEM lib (_ssl.c:4109)')))

 

 

 

 

 

request = urllib2.Request("https://api.lithium.com/lsi-data/v1/data/export/community/communityid?fromDate=20210701&toDate=20210707")
base64string = base64.b64encode(('%s:' % access_token).encode('utf-8'))
request.add_header("Authorization", "Basic %s" % base64string)
request.add_header("client-id", client_id)
request.add_header("Accept", "application/json") 

response = urllib2.urlopen(request)
print(response.read())

 

 

Output:

 

---> 10 response = urllib2.urlopen(request)

HTTPError
: HTTP Error 500: Internal Server Error

1 Reply

  • It sounds like you have an issue with your SSL certificate chain on the machine where you're running the script.  (Check out this Stackoverflow thread.)

    Are you by chance running the commands from an internal server/workstation behind your company's firewall?  Because I used to hit a similar SSO certification error with the Jive Data Export Service (api.jivesoftware.com) because of how our internal network traffic flowed.

    If so then as a longer-term solution I would recommend engaging with your IT team to get the proper SSL cert files for your internal cert chain and get them installed on the machine.

    But in the short-term, a quicker (but insecure) way to get around the error is to include the verify=False parameter in your requests.get() method call:

    date_range = {
        'fromDate': '20210630',
        'toDate': '20210707'
    }
    headers = {
        'client-id': client_id,
        'Accept': 'application/json'
    }
    uri = 'https://api.lithium.com/lsi-data/v1/data/export/community/communityid'
    response = requests.get(uri, params=date_range, auth=(access_token, ''), headers=headers, verify=False)

     

    Hope this helps!

    P.S. I'm planning to build some Bulk API query functionality into my open-source khoros Python library in the next month or two, which should make things even easier.