request.post to a php server that requires info of a 2D array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

request.post to a php server that requires info of a 2D array

Ive been playing around with the servers of our company for a while, posting data to .php to make my work easier, using python. A recent problem is: this time the .php server requires a 2D array, I’m not familiar with php at all, but what the server requires really is something like somedata[[‘key1’]] somedata[[‘key2’]] And it seems to me pretty naturally that I should do a [{‘key1’: value1, ‘key’2: value2}] in my python codes. There’s no other way to create a 2D array where the values have keys, in python, right? The problem is when I post the dict-in-list data, the server keeps saying the parameters are wrong. I’ve asked the guy in our tech team why this is happening, but he doesn’t know python nor the answer. I’ve also searched “posting to php from python” on stackoverflow, and didn’t quite find similar questions. I’m a bit afraid that this is a far too stupid question that no one bothers to ask, but it’s really weird that since there’s no other way to represent [[‘key1’=> value1, ‘key2’=> value2]] In python than a dictionary in a list. Is there? Any help would be appreciated. I personally think that the tech guy didn’t write it correctly on his part, I’ll never know. Ps. I’m also confused because if I get data from a php server that is a similar 2D array, it simply translates into a dictionary inside a list. In fact, that’s how I got the list data in the first place: first getting it from one php, then passing it to another. My code: https://code.sololearn.com/c0jj85CH4zoQ/?ref=app

9th Feb 2020, 3:44 PM
GaryIsHere
1 Answer
0
ive fixed it myself. never pass something like [{}] to php from python. pass a json directly
10th Feb 2020, 9:46 AM
GaryIsHere