Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions vk_api/vk_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
"""
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему-то гитхаб изменение показывает. Возможно у тебя \r\n переносы, вроде должны быть \n

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В GitKraken такого нет...

:authors: python273
:license: Apache License, Version 2.0, see LICENSE file
Expand Down Expand Up @@ -79,6 +79,9 @@ class VkApi(object):
`login` и `password` необходимы для автоматического получения токена при помощи
Implicit Flow авторизации пользователя и возможности работы с веб-версией сайта
(включая :class:`vk_api.audio.VkAudio`)

:param session: Кастомная сессия со своими параметрами(из библиотеки requests)
:type session: :class:`requests.Session`
"""

RPS_DELAY = 0.34 # ~3 requests per second
Expand All @@ -87,7 +90,7 @@ def __init__(self, login=None, password=None, token=None,
auth_handler=None, captcha_handler=None,
config=jconfig.Config, config_filename='vk_config.v2.json',
api_version='5.92', app_id=6222115, scope=DEFAULT_USER_SCOPE,
client_secret=None):
client_secret=None, session=None):

self.login = login
self.password = password
Expand All @@ -101,11 +104,12 @@ def __init__(self, login=None, password=None, token=None,

self.storage = config(self.login, filename=config_filename)

self.http = requests.Session()
self.http.headers.update({
'User-agent': 'Mozilla/5.0 (Windows NT 6.1; rv:52.0) '
'Gecko/20100101 Firefox/52.0'
})
self.http = session or requests.Session()
if not session:
self.http.headers.update({
'User-agent': 'Mozilla/5.0 (Windows NT 6.1; rv:52.0) '
'Gecko/20100101 Firefox/52.0'
})

self.last_request = 0.0

Expand Down