Hello.

I am writing a bot to send entries from Telegram to VK I write in Python 3.5. To send a message I use this function:

def post(message): print(urllib.request.urlopen('https://api.vk.com/method/wall.post?from_group=1&owner_id='+owner_id+'&message='+message+'&access_token='+access_token+'&v=5.62').read()) 

In response, API VC sends me an error with a link to confirm actions:

 {"error":{"error_code":17,"error_msg":"Validation required: please open redirect_uri in browser 246620520","request_params":[{"key":"oauth","value":"1"},{"key":"method","value":"wall.post"},{"key":"from_group","value":"1"},{"key":"owner_id","value":"(Группа)"},{"key":"message","value":"TestForBot"},{"key":"v","value":"5.62"}],"redirect_uri":"https:\\/\\/m.vk.com\\/login?act=security_check&api_hash=(Хэш)"}} 

Record after request to API did not appear. I tried to substitute crutches and did everything as follows:

 def post(message): print('https://api.vk.com/method/wall.post?from_group=1&owner_id='+owner_id+'&message='+message+'&access_token='+access_token+'&v=5.62') validate=str(urllib.request.urlopen(Запрос к API).read()) print(validate) for i in range(len(validate)-16): if validate[i:i+16:]=='"redirect_uri":"': i+=16 validate_url='' while validate[i]!='"': if validate[i]!='\\': validate_url+=validate[i] i+=1 break requests.get(validate_url) 

That is, I made it so that after a request to the API, Python would open the link that had to be opened to confirm actions. Again nothing.

Tell me what am I doing wrong? If I send a request through the browser, then everything goes fine, without errors. Only through Python this happens.

I am using Python 3.5

  • one
  • You need to open this link with your hands in the actual browser itself and with the same hands fulfill the requirements that will be written there. - andreymal
  • And no way to automate this process? - ABLPHA

1 answer 1

Quite rarely this error means exactly what is written there . I mean, most likely, opening the link in the browser will not solve the problem and the error will appear again and again, not allowing you to call any methods from under the token you are using. Opening a link in the browser can only help if you access the API from the same IP from which the user is logged in to VK.

But the most likely cause of this error is the absence of two-factor authorization on the account. That is, you need to bind the phone number to the profile of VKontakte and configure the input there using one-time codes via SMS.

The problem is that you make a request to the API from an IP address that is different from the one from which you are logged in to VKontakte. And since you have not yet configured two-factor authentication, then VKontakte considers it suspicious and prohibits accessing the API on behalf of the account you are using from the “left” IP address. I had many accounts and I could not access the API from a third-party server without two-factor authentication.

It is very sad that the vile VK API documentation is forcing people to look for a solution to these undocumented problems on Stack Overflow.

  • Why undocumented, even right in the answer there is a link to the documentation - andreymal
  • one
    @andreymal, I suppose you did not read the contents of that link before you decided to write a comment. Or very carelessly read my answer. - neluzhin
  • And what is wrong? Error 17 in the question, error 17 by reference, it also says that the link should be opened in the browser and everything will be solved. As at war with this error for the last four years, I confirm that opening a link in the browser solves everything. What else? - andreymal
  • And yes, I don’t have and never had two-factor authentication, but still opening a link in the browser always helped smoothly - andreymal
  • @andreymal, this is because you are making requests from the same IP from which you are sitting in VC. And the author writes not a standalone application, but a bot, which he will hardly keep on the local machine. How many redirect_uri do not open does not help, because when you open redirect_uri, VKontakte remembers the IP address that opened this very link, and, in fact, removes the “stub” for this address in the form of the 17th error. - neluzhin