Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not post using python #53

Closed
macomzzl opened this issue Jul 19, 2016 · 3 comments
Closed

can not post using python #53

macomzzl opened this issue Jul 19, 2016 · 3 comments

Comments

@macomzzl
Copy link

If I use python to post data to this compiler server api, it returns "invalid input".
I use urllib2 to post. And I found that the request data the server received is not a json.

@tzikis
Copy link
Member

tzikis commented Jul 19, 2016

Hey @macomzzl does the CURL example work for you? It's hard to know how to help you without knowing exactly the request you're sending

@macomzzl
Copy link
Author

@tzikis the CURL example is ok for me. But my application uses python to write. So I want to use python to post data to the compiler server.
Here is my test using python. And it doesn't work.

import urllib
import urllib2

json_data = {
                     'files':[{"content": "void setup()\n{\n  pinMode(0, OUTPUT);\n}\n\nvoid loop()\n{\n  digitalWrite(0,HIGH);\n\n}", "filename": "Arduino.ino"}],
                     'libraries':[], #key:[]
                     'format':"hex",
                     'version':'105',
                     'build':{
                        'mcu':'atmega328p',
                        'f_cpu':'16000000L',
                        'core':'arduino',
                        'variant':'standard'
                        }

                    }

url="http://the_url_of_your_compiler/authorizationKey/API_Version"
req = urllib2.Request(url)
print urllib.urlencode(json_data)
req.add_data(urllib.urlencode(json_data))
resp = urllib2.urlopen(req)

print resp.read()

@tzikis
Copy link
Member

tzikis commented Jul 20, 2016

I'm afraid I can't help since I don't know much about python. You'll need to find a way to see what kind of HTTP message your python script creates, vs the HTTP message the cURL command creates

I'll have to close this issue, since it isn't related to the project itself

@tzikis tzikis closed this as completed Jul 20, 2016
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

No branches or pull requests

2 participants