can anyone guide me in the right direction when it comes to http requests with python? What I'm after is a Excel-VBA add-in which will track which workbooks the user opens and when etc. While that's already done, I would now like to get the information to a database.
For that purpose I can imagine running a very simple Python server which would be used to store the information. The question thus is, how do I set up a simple http server so that VBA can post a simple string which then gets stored?
Thanks!
EDIT:
Thanks chf! I went ahead and followed your advice - I replaced flask with django though as I had some brief experience with that. I've got my first API ever created now but can't post using the VBA code you posted. I can do httpie like so: "http POST http:/127.0.0.1 name="somename" workbookname="someworkbook".
Sub TestFramework()
Dim newClient As New WebClient
Dim newRequest As New WebRequest
Dim Response As WebResponse
newClient.BaseUrl = "http://127.0.0.1:8000/api/create/"
newRequest.Method = HttpPost
newRequest.Format = WebFormat.plaintext
newRequest.AddBodyParameter "name", "somename"
newRequest.AddBodyParameter "workbook_name", "Sheet1"
Set Response = newClient.Execute(newRequest)
End Sub
Any chance you might point me to the right way?
RuntimeError: You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. Change your form to point to 127.0.0.1:8000/api/create/ (note the trailing slash), or set APPEND_SLASH=False in your Django settings. [03/Aug/2016 20:13:18] "POST /api/create HTTP/1.1" 500 60534
Edit2: nevermind, got it working :)