2016-08-01 69 views
0

任何人都可以引导我正确的方向,当涉及到HTTP请求与Python?我所追求的是一个Excel-VBA加载项,它将跟踪用户打开哪些工作簿以及何时等。虽然已经完成,但现在我想将信息提供给数据库。HTTP请求(Python + VBA)

为此我能想象运行这将被用来存储的信息很简单的Python服务器。因此,问题是,我如何设置一个简单的http服务器,以便VBA可以发布一个简单的字符串然后存储?

谢谢!

编辑:

谢谢chf!我继续跟着你的建议 - 我用django替换了烧瓶,因为我有一些简短的经验。我已经创建了我的第一个现在创建的API,但不能发布使用您发布的VBA代码。我可以做httpie像这样: “HTTP POST HTTP:/127.0.0.1名=” 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 

你可能指向我正确的方式任何机会

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:请不要介意,得到它的工作:)

回答

1

尼斯项目 可以使用Flask为Python的一部分,建立一个小型的REST API和VBA的一部分,你可以使用VBA-WEB消耗的是API

这两个Flask比VBA-WEB都有很多实例记录。 我在Excel中使用了许多小型“SAK”(瑞士军刀)实用程序中的VBA-WEB,它非常实用且功能强大。 对于json输出的一些休息apis Flask是一个不错的使用工具。