jessamynsmith / eggtimer-server

Server for online menstrual tracker
https://eggtimer.jessamynsmith.ca
MIT License
49 stars 17 forks source link

Request from Arduino #9

Closed sabas1080 closed 8 years ago

sabas1080 commented 8 years ago

Hi I 'm trying to make a request from Arduino , but can not receive any response from the server,

"GET /api/v2/periods/ HTTP/1.1\r\n"
                    "Host: eggtimer.herokuapp.com\r\n"
                    "User-Agent: ESP8266\r\n"
                    "Content-Type: application/json\r\n"
                    "Authorization: Token "+ MyApi_Key + "\r\n";

Could you help me a little to make the request ?

Thanks

jessamynsmith commented 8 years ago

I saw the failed requests coming in last night. It looks as if the user is not being logged in correctly.

A valid curl request would look like the following:

$ curl -v -k -X GET -H "Content-Type: application/json" -H 'Authorization: Token 37b13ab6aefe34344dd0d853c9491e8de4caa27c' "https://eggtimer.herokuapp.com/api/v2/statistics/"
*   Trying 50.16.215.101...
* Connected to eggtimer.herokuapp.com (50.16.215.101) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: *.herokuapp.com
* Server certificate: DigiCert SHA2 High Assurance Server CA
* Server certificate: DigiCert High Assurance EV Root CA
> GET /api/v2/statistics/ HTTP/1.1
> Host: eggtimer.herokuapp.com
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Type: application/json
> Authorization: Token <token>
> 
< HTTP/1.1 200 OK
< Connection: keep-alive
< Server: gunicorn/19.3.0
< Date: Sun, 17 Jan 2016 17:24:36 GMT
< Transfer-Encoding: chunked
< Allow: GET, POST, HEAD, OPTIONS
< Vary: Accept, Cookie
< X-Frame-Options: SAMEORIGIN
< Content-Type: application/json
< Via: 1.1 vegur
< 
* Connection #0 to host eggtimer.herokuapp.com left intact
{ ... result data ... }

Are you using https?

jessamynsmith commented 8 years ago

So far, I haven't been able to duplicate the issue you are seeing. I have tried http and also invalid tokens, and I get 301 and 403 respectively. I will continue investigating.

sabas1080 commented 8 years ago

Thanks, yes i using https with ESP8266.

I get no mistake, even 301 or 400

keep trying,

jessamynsmith commented 8 years ago

Indeed, you've found a path on the server that results in a 500. I'll see what I can do to reproduce and fix it.

sabas1080 commented 8 years ago

I can do POST correctly, but does not respond GET

an apology for the inconvenience

sabas1080 commented 8 years ago

I solved the problem , thanks

jessamynsmith commented 8 years ago

I'm glad you sorted it out. Would you be willing to write out the solution here, in case anyone else encounters it?

sabas1080 commented 8 years ago

Yes!!

My code:

https://gist.github.com/sabas1080/812d680019c1cfa34158

Thanks for all