Skip to content

Commit

Permalink
Use specific user agent for Stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Harmon758 committed Jan 25, 2021
1 parent 4fc23e6 commit 5994c4b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tweepy/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,6 +16,7 @@
from requests_oauthlib import OAuth1
import urllib3

import tweepy
from tweepy.error import TweepError
from tweepy.models import Status

Expand Down Expand Up @@ -44,12 +46,18 @@ def __init__(self, consumer_key, consumer_secret, access_token,
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"

Expand Down

0 comments on commit 5994c4b

Please sign in to comment.