Skip to content

Commit 1d153da

Browse files
dailycodingf2prateek
authored andcommitted
Library sends a User-Agent header in the form of analytics-python/{library_version} as per RFC 7231. (#107)
1 parent 3decd60 commit 1d153da

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

analytics/request.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from dateutil.tz import tzutc
33
import logging
44
import json
5+
from analytics.version import VERSION
56

67
from requests.auth import HTTPBasicAuth
78
from requests import sessions
@@ -19,7 +20,10 @@ def post(write_key, host=None, **kwargs):
1920
url = remove_trailing_slash(host or 'https://api.segment.io') + '/v1/batch'
2021
auth = HTTPBasicAuth(write_key, '')
2122
data = json.dumps(body, cls=DatetimeSerializer)
22-
headers = { 'content-type': 'application/json' }
23+
headers = {
24+
'Content-Type': 'application/json',
25+
'User-Agent': 'analytics-python/' + VERSION
26+
}
2327
log.debug('making request: %s', data)
2428
res = _session.post(url, data=data, auth=auth, headers=headers, timeout=15)
2529

0 commit comments

Comments
 (0)