Answer the question
In order to leave comments, you need to log in
Url address in get request in python 3.6 is truncated, why?
There is a simple get request
import requests
def send_message (peer_id,message='',attachment='',forward_messages='',token=""):
r=requests.get('https://api.vk.com/method/messages.send',params={'peer_id':peer_id,'message':message,'attachment':attachment,'forward_messages':forward_messages,'v':'5.71','access_token':token})
print((r.content).decode('utf-8'))
send_message (2000000723,'t'*4000)
<html>
<head><title>414 Request-URI Too Long</title></head>
<body bgcolor="white">
<center><h1>414 Request-URI Too Long</h1></center>
<hr><center>nginx/0.3.33</center>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
Send data via POST, not GET. Usually a GET request is limited to 64k, but depends on the web server settings.
import requests
def send_message (peer_id,message='',attachment='',forward_messages='',token=""):
r=requests.post('https://api.vk.com/method/messages.send', data ={'peer_id':peer_id,'message':message,'attachment':attachment,'forward_messages':forward_messages,'v':'5.71','access_token':token})
print((r.content).decode('utf-8'))
You should pay attention to the py-vkontakte library , which allows you to work with the vk.com API.
>>> import vk
>>> api = vk.Api(TOKEN)
>>> group = api.get_group('team') # vk.com/team
>>> group.send_messages(user_id, message='Hello')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question