Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two headers missing #3

Open
mallyvai opened this issue Oct 19, 2016 · 1 comment
Open

Two headers missing #3

mallyvai opened this issue Oct 19, 2016 · 1 comment

Comments

@mallyvai
Copy link

mallyvai commented Oct 19, 2016

As of the date of this posting, I was unable to get this library working. Here's what I did instead:

  1. I got a basic cURL command working on the command line
  2. Mapped that to a new mini-client:

Here's my working mini-client:


class DripClient(object):
    token = None
    account_id = None
    api_url = 'https://api.getdrip.com/v2'

    def __init__(self, token, account_id):
        self.token = token
        self.account_id = account_id

        self.headers = {
            'Content-Type': 'application/vnd.api+json',
            'User-Agent': 'offerletter.io'
        }

    def get_campaigns(self):
        url = '{api_url}/{account_id}/campaigns/'.format(api_url = self.api_url,
                                                         account_id = self.account_id)
        response = requests.get(url, headers=self.headers, auth=requests.auth.HTTPBasicAuth(self.token, ''))
        return response

Key differences from this library:

  1. auth=HTTPBasicAuth is supplied, instead of adding another key in the headers dict
  2. A user-agent= 'my-site' is supplied in the header

HTH,
Vaibhav

@matthiasmiller
Copy link

Alternative approach in init:

import base64
self.headers['Authorization'] = 'Basic %s' % base64.b64encode(self.token)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants