GET to Flask server; Status code: 200 vs. Status code 606
Hi guys, first of all: Thanks for your great project... I am using your driver located here: Drivers/SIM800L.py
I don't know where can be a problem and i am writing here entire my scenario and specific information which i know:
I am using latest version:
modem.get_info()
> 'SIM800 R14.18'
and my device is connected on Internet:
modem.get_ip_addr()
>> '100.67.x.x'
# or
url = 'http://checkip.dyn.com/'
response = modem.http_request(url, 'GET')
print('Response status code:', response.status_code)
>> Response status code: 200
All these my experiments are okay.
And here is my problem:
My webserver is based on Flask (with NGINX server) and i have simple and basic endpoint:
@blueprint.route('/api/', methods=['GET'])
def index():
request_status = {'status': 'OK'}
return jsonify(request_status), 200
When i try simple request to my API with requests library ("normal" Python 3.5+):
import requests
r = requests.get('https://ha.datain.app/api/')
print(r.status_code, '/ ', r.content)
>> 200 / b'{"status":"OK"}\n'
And everything looks good...
But when i try similar request to API over my TTGO T-Call SIM800 with code:
print('\nNow running demo http GET...')
url = 'https://ha.datain.app/api/'
response = modem.http_request(url, 'GET')
print('Response status code:', response.status_code)
print('Response content:', response.content)
i see response:
Response status code: 606
Response content:
A am pasting here all info from your additional log:
=== url = 'https://ha.datain.app/api/'
=== response = modem.http_request(url, 'GET')
=== print('Response status code:', response.status_code)
=== print('Response content:', response.content)
Now running demo http GET...
DEBUG: Writing AT command "b'AT+SAPBR=2,1\r\n'"
DEBUG: Read "b'AT+SAPBR=2,1\r\r\n'"
DEBUG: Read "b'+SAPBR: 1,1,"100.67.239.103"\r\n'"
DEBUG: Read "b'\r\n'"
DEBUG: Detected pre-end
DEBUG: Read "b'OK\r\n'"
DEBUG: Detected exact end
DEBUG: Returning "b'+SAPBR: 1,1,"100.67.239.103"'"
DEBUG: Close the http context if left open somehow...
DEBUG: Writing AT command "b'AT+HTTPTERM\r\n'"
DEBUG: Read "b'AT+HTTPTERM\r\r\n'"
DEBUG: Read "b'ERROR\r\n'"
DEBUG: Http request step #1.1 (inithttp)
DEBUG: Writing AT command "b'AT+HTTPINIT\r\n'"
DEBUG: Read "b'AT+HTTPINIT\r\r\n'"
DEBUG: Read "b'OK\r\n'"
DEBUG: Detected exact end
DEBUG: Returning "b''"
DEBUG: Http request step #1.2 (sethttp)
DEBUG: Writing AT command "b'AT+HTTPPARA="CID",1\r\n'"
DEBUG: Read "b'AT+HTTPPARA="CID",1\r\r\n'"
DEBUG: Read "b'OK\r\n'"
DEBUG: Detected exact end
DEBUG: Returning "b''"
DEBUG: Http request step #1.3 (enablessl)
DEBUG: Writing AT command "b'AT+HTTPSSL=1\r\n'"
DEBUG: Read "b'AT+HTTPSSL=1\r\r\n'"
DEBUG: Read "b'OK\r\n'"
DEBUG: Detected exact end
DEBUG: Returning "b''"
DEBUG: Http request step #2.1 (initurl)
DEBUG: Writing AT command "b'AT+HTTPPARA="URL","https://ha.datain.app/api/"\r\n'"
DEBUG: Read "b'AT+HTTPPARA="URL","https://ha.datain.app/api/"\r\r\n'"
DEBUG: Read "b'OK\r\n'"
DEBUG: Detected exact end
DEBUG: Returning "b''"
DEBUG: Http request step #2.2 (doget)
DEBUG: Writing AT command "b'AT+HTTPACTION=0\r\n'"
DEBUG: Read "b'AT+HTTPACTION=0\r\r\n'"
DEBUG: Read "b'OK\r\n'"
DEBUG: Read "b'\r\n'"
DEBUG: Detected pre-end
DEBUG: Read "b'+HTTPACTION: 0,606,0\r\n'"
DEBUG: Detected startwith end (and adding this line to theoutput too)
DEBUG: Returning "b'OK+HTTPACTION: 0,606,0'"
DEBUG: Response status code: "606"
DEBUG: Http request step #4 (getdata)
DEBUG: Writing AT command "b'AT+HTTPREAD\r\n'"
DEBUG: Read "b'AT+HTTPREAD\r\r\n'"
DEBUG: Read "b'OK\r\n'"
DEBUG: Detected exact end
DEBUG: Returning "b''"
DEBUG:
DEBUG: Http request step #4 (closehttp)
DEBUG: Writing AT command "b'AT+HTTPTERM\r\n'"
DEBUG: Read "b'AT+HTTPTERM\r\r\n'"
DEBUG: Read "b'OK\r\n'"
DEBUG: Detected exact end
DEBUG: Returning "b''"
Response status code: 606
Response content:
I think that "problem" is probably on my server, but unfortunately i don't understand, how to prepare my endpoint for request from your modem driver. Please, can you help me with server response what you expecting it?
Thank you for your support. Lukas Sliacky
Hi @LukasSliacky,
The 606 error seems to be a problem with the SIM800 firmware itself: your server is using a SSL version which is "too new" for the SIM800. See here: https://stackoverflow.com/questions/50764833/sim800-https-606-error
Either downgrade your web server SSL, or proper SSL support should be implemented (building on top of PR https://github.com/pythings/Drivers/pull/5).
Hi @sarusso,
oh, of course. You are absolutely right ... I spent lot of time with googling, but progably i went to wrong way. On my project server i temporarily disabled SSL and after this change, everything works good.
Really thanks for your support.
Lukas Sliacky
I had the same problem, but managed to solve it. You can allow Nginx to accept TLSv1 (the only version supported by sim800L) and the module will send data over ssl to your server.
Add these directives to your nginx server config:
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;