GithubHelp home page GithubHelp logo

Comments (9)

0417taehyun avatar 0417taehyun commented on August 15, 2024 1

Hi, @illpack !

I am sorry that I just describe my solution roughly.
I recommend to use requests package, and call the API through the URL instead of SDK.

The below one is an example source code.

from requests import Response, Session

class Mixpanel:
    def __init__(self):
        self.session: Sesison = Session()
        self.adapter: HTTPAdapter = HTTPAdapter(max_retries=20)
        self.session.mount("htttps://", adapter=self.adapter)
        self.session.mount("http://", adapter=self.adapter)        
        
    def track(self, username, event_name, data={}, request=None):
        response: Response = self.session.post(
              url="https://api.mixpanel.com/track",
              headers={
                  "Accept": "text/plain",
                  "Content-Type": "application/json",
                  "Connection": "close".   # This header is my solution.
              },
              json=[
                  {
                      "event": YOUR_EVENT_NAME,
                      "properties": {
                          "token": YOUR_TOKEN,
                          ...
                      },
                  }
              ],
        )

If you want to use asynchronous HTTP requests, you can use aiohttp package instead of requests.
I think there are no ways to change the header parameters if you use the SDK.

You can check the all API lists from the documents, and if you want to use the track method -API-, check Track Events

from mixpanel-python.

illpack avatar illpack commented on August 15, 2024 1

Thanks a lot @0417taehyun that looks reasonable, I will try your approach.

from mixpanel-python.

illpack avatar illpack commented on August 15, 2024 1

Sure thing @0417taehyun I will give it a try shortly and monitor it and keep you posted!

from mixpanel-python.

illpack avatar illpack commented on August 15, 2024

Same problem here - any hints?

from mixpanel-python.

0417taehyun avatar 0417taehyun commented on August 15, 2024

@illpack

Hi, I solved this issue to change the Connection header argument.
The default value is keep-alive, and I change it to close.

from mixpanel-python.

illpack avatar illpack commented on August 15, 2024

Hi @0417taehyun I am glad you managed to solve it! I am using the Mixpanel client for Python, but can't see a clear reference to your solution, could you maybe provide a small example of how you applied it?

This is my implementation:

from mixpanel import Consumer, Mixpanel

class MixpanelClient:
    def __init__(self):
        self.client = Mixpanel(
            MXP_TOKEN,
            consumer=Consumer(api_host=MXP_HOST),
        )
        self.api_key = MXP_API_KEY

    async def track(self, username, event_name, data={}, request=None):
        [...]
        self.client.track(username, event_name=event_name, properties=data)

Thanks a lot!

from mixpanel-python.

0417taehyun avatar 0417taehyun commented on August 15, 2024

@illpack

I am glad I could help you! Would you mind sharing whether my approach works for your situation or not?
I am curious to know if it's successful.

from mixpanel-python.

illpack avatar illpack commented on August 15, 2024

Hi @0417taehyun I have deployed your solution this morning and it seems to have solved the issue, it has not ocurred again in the last 4 hours. Thank you!! 🎉

from mixpanel-python.

0417taehyun avatar 0417taehyun commented on August 15, 2024

Hi, @illpack !

It is glad to hear that you solve the issue! Have a nice day 😄

from mixpanel-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.