0

I believe this is a simple data type issue, so the next paragraph is optional but possibly helpful background:

I'm using Mixpanel's Export method with the Python API. I downloaded the library here (https://mixpanel.com/site_media/api/v2/mixpanel.py), and have been modifying it for the raw event data export described here (https://mixpanel.com/docs/api-documentation/exporting-raw-data-you-inserted-into-mixpanel). The raw data export has a json per line, each describing an event.

def request(self, methods, params, format='json'):
    """
        methods - List of methods to be joined, e.g. ['events', 'properties', 'values']
                  will give us http://mixpanel.com/api/2.0/events/properties/values/
        params - Extra parameters associated with method
    """
    params['api_key'] = self.api_key
    params['expire'] = int(time.time()) + 600   # Grant this request 10 minutes.
    params['format'] = format
    if 'sig' in params: del params['sig']
    params['sig'] = self.hash_args(params)

    request_url = '/'.join([self.ENDPOINT, str(self.VERSION)] + methods) + '/?' + self.unicode_urlencode(params)

    data = []
    request = urllib2.urlopen(request_url, timeout=120)     # this is a file-like object

    # this block returns a list containing one json
    for line in request:
        data.append(json.loads(line))

    return data

This is the definition of the request method of the Mixpanel object. The script it's a part of initialises an instance of the object, feeds in the correct credentials, and prints the output of this method. Basically:

  • request is a file-like object, and should have a json document on each line
  • i'm trying to iterate through those lines (which are jsons) and append them to a list called data, then return it.
  • there should be a lot of lines, but i'm only getting one

0 Answers0