Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

python - In Flask, why do 'position' is not recognized as a valid JSON

I'm running a Python app using Flask. The app shows an HTML form that the user fills and press send. When the button is click, the app sends the information to the backend server. I'm trying to send the following JSON to the server:

"coordinates": [
  {
    "dateTime": "2020-03-18T18:16:00.000Z",
    "latitude": "N45 40.1111",
    "longitude": "W73 40.2222",
    "position": "position"
  }
],

Here is how I create my object in the Python app:

class Coordinate(object):
    def __init__(self, 
                dateTime='2018-10-21T15:36:00.000Z', 
                latitude='N45 40.1111', 
                longitude='W73 40.2222'):
        self.dateTime = dateTime
        self.latitude = latitude
        self.longitude = longitude
        self.positio = "positio"
        self.position = "position"
        self.bbb = "bbb"

self.status['coordinates'] = [Coordinate(form['dateTime'], form['latitude'], form['longitude']).__dict__]

Here is my request that sends the data to the backend server:

requests.put(url=f'https://{url}/target/{self.id}',headers={'Authorization': f'Bearer {self.token}', 'Content-Type': 'application/json'}, json={"status": self.status})

But the JSON that I see is this one:

"coordinates": [
  {
    "dateTime": "2020-03-18T18:16:00.000Z",
    "latitude": "N45 40.1111",
    "longitude": "W73 40.2222",
    "positio": "positio"
    "bbb": "bbb"
  }
],

position is not in the JSON of the request! I have added positio and bbb just to make sure I'm not crazy.

My initial guess would be that position is a sort of reserved keyword, but I cannot see any information about that.

question from:https://stackoverflow.com/questions/65835067/in-flask-why-do-position-is-not-recognized-as-a-valid-json

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...