From 5994c4b4005f5f909609ff04765b784fcbe9479c Mon Sep 17 00:00:00 2001 From: Harmon Date: Mon, 25 Jan 2021 13:10:07 -0600 Subject: [PATCH] Use specific user agent for Stream --- tweepy/streaming.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tweepy/streaming.py b/tweepy/streaming.py index 153bed4..0383716 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -7,6 +7,7 @@ import json import logging from math import inf +from platform import python_version import ssl from threading import Thread from time import sleep @@ -15,6 +16,7 @@ import requests from requests_oauthlib import OAuth1 import urllib3 +import tweepy from tweepy.error import TweepError from tweepy.models import Status @@ -44,12 +46,18 @@ class Stream: self.running = False self.session = None self.thread = None + self.user_agent = ( + f"Python/{python_version()} " + f"Requests/{requests.__version__} " + f"Tweepy/{tweepy.__version__}" + ) def _connect(self, method, endpoint, params=None, headers=None, body=None): self.running = True if self.session is None: self.session = requests.Session() + self.session.headers["User-Agent"] = self.user_agent url = f"https://stream.twitter.com/1.1/{endpoint}.json" -- 2.25.1