S
S
sharkyyy32019-09-07 09:22:17
Python
sharkyyy3, 2019-09-07 09:22:17

How to send POST request to VK API?

Hi all!
In general, I'm trying to send a POST request:

r = requests.post('api.vk.com/method/stories.markSeen?stories=500824785_456239034&access_token=193333333333f74b498fa45e41cc62c384baa28db89819e301b3a88cf6b5a460aef408d93de0&v=5.101', params=field)

What comes in response:
{"error":{"error_code":3,"error_msg":"Unknown method passed","request_params":[{"key":"stories","value":"500824785_456239034"},{"key":"v","value":"5.102"},{"key":"method","value":"stories.markSeen"},{"key":"oauth","value":"1"}]}}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Ordec, 2019-09-07
@Ordec

Not strong in Python, but your uri looks like a GET request.
in POST requests, the data must be passed in the body of the request. How it should look like:

data = ['stories': '500824785_456239034', 'access_token': 'token', 'v': '5.101'];
r = reqiest.post('url/method.stories/', data);

PS For the future, it's better not to send your token. If possible, generate a new one.

S
Sergey Sokolov, 2019-09-07
@sergiks

markSeen()Only bookmarks have a method : fave.markSeen()
The resulting error message is about this very reason and says:
"Unknown method passed"
Try calling existing VK API methods .

For example users.get()
import requests

payload = {
  'access_token': 'XXXXXXX',
  'v': '5.101'
}

r = requests.post('https://api.vk.com/method/users.get', data=payload)

print(r.text)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question