T
T
toha_man2019-02-15 09:51:15
Python
toha_man, 2019-02-15 09:51:15

How to add schema to string in json format in python?

Good morning, gentlemen. I am writing a small bot for VK. I had to switch from the vk_api library to vk, in the latter the getLongPollServer functions similar in functionality are implemented in a rather interesting way.
In one case (for groups) this function returns the object { server: [ https://blablabla.com] } with the protocol prefix, and in the second case (for messages) it returns only the domain. This is where the difficulty arises later in the code, where you need to call the line

longPoll = post('%s'%server, data = {'act': 'a_check',
                                         'key': key,
                                         'ts': ts,
                                         'wait': 25}).json()

and here the interpreter swears that there is no schema. Adding it in different ways, ala - server = 'https://' + server and converting server to json, does not give success - error - invalid JSON format

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
toha_man, 2019-02-24
@toha_man

I don't even know why, but now the
server = 'http://' + server method, as well as
longPoll = post('http://' + '%s'%server '
both started working, although yesterday there was an error, joking Besides...

V
Vladislav Klimanov, 2019-02-18
@ahmpro

Parse the server string into components using urlparse , replace scheme with the one you need (http/https) and assemble it back into a string

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question