Skip to content

Conversation

@bmagistro
Copy link
Contributor

encode the ap object before urequests to ensure the content length gets set correctly.

@ipl31
Copy link
Collaborator

ipl31 commented Jan 23, 2018

Funny, I think Matt originally was using the data param and json serializing it. I suggested using the json param to reduce the amount of the code. Does this fix the issue we were seeing?

@robotlandman
Copy link
Owner

Another thought - the try block may be hiding any issues this change introduces. Can you put the ‘ujson.dumps().encode()’ outside the try and report back? I want to make sure that’s not the cause of your red light versus something server-side.

@bmagistro
Copy link
Contributor Author

A quick test with the line moved doesn't appear to change things. Will push as well.

I have a stripped down version of the server (no mysql) that I was using to say can I get the json and that returns valid json. Not sure I have the app side up correctly.

@bmagistro
Copy link
Contributor Author

Issue server side on insert. Will look at it more tomorrow.
Initial error is u"Incorrect string value: '\\xE2\\x98\\x83' for column 'ssid'
If you change the ssid, to have a .decode('utf8') the message changes to 'ascii' codec can't encode character u'\u2603'

@ipl31
Copy link
Collaborator

ipl31 commented Jan 25, 2018

I am closing this out because the DB encoding fixed the issues we were seeing. Feel free to re-open if I am incorrect.

@ipl31 ipl31 closed this Jan 25, 2018
@ipl31
Copy link
Collaborator

ipl31 commented Jan 25, 2018

Reopening. After talking to @bmagistro I understand that this is required in addition to the table character set change.

@ipl31 ipl31 reopened this Jan 25, 2018

encoded_ap_neighbors = ujson.dumps(ap_neighbors).encode('utf8')
try:
response = urequests.post(config.UPLOAD_URL + mac_id, json=ap_neighbors, headers={'Content-Type': 'application/json', 'User-Agent': 'WarBadge Experimental ShmooCon 2018'})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please test the following?

response = urequests.post(config.UPLOAD_URL + mac_id, json=ap_neighbors, ensure_ascii=False, headers={'Content-Type': 'application/json', 'User-Agent': 'WarBadge Experimental ShmooCon 2018'})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look like it is posting successfully. Adding some details to the try/except, looks like it is "unexpected keyword argument ensure_ascii". Digging into it, the ujson library doesn't have the parameter ensure_ascii. The library urequests it is using usjon to do the dump but doesn't call encode, if it did, the the json parameter would work just fine. It appears the key difference here is the .encode('utf8').

@ipl31
Copy link
Collaborator

ipl31 commented Jan 25, 2018

I put a question inline in the change set. Please look at the "Files changed" tab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants