我正在尝试使用requests模块重写一些旧的python代码.目的是上传附件.邮件服务器需要以下规范:
https://api.elasticemail.com/attachments/upload?username=yourusername&api_key=yourapikey&file=yourfilename
Run Code Online (Sandbox Code Playgroud)
有效的旧代码:
h = httplib2.Http()
resp, content = h.request('https://api.elasticemail.com/attachments/upload?username=omer&api_key=b01ad0ce&file=tmp.txt',
"PUT", body=file(filepath).read(),
headers={'content-type':'text/plain'} )
Run Code Online (Sandbox Code Playgroud)
没有找到如何在请求中使用正文部分.
我设法做了以下事情:
response = requests.put('https://api.elasticemail.com/attachments/upload',
data={"file":filepath},
auth=('omer', 'b01ad0ce')
)
Run Code Online (Sandbox Code Playgroud)
但不知道如何使用文件内容指定正文部分.
谢谢你的帮助.奥马尔.
我正在尝试使用zeromq框架实现pub子设计模式.我们的想法是推出订阅者,然后推出发布者.订阅者将收听100条消息,发布者将发布100条消息.到目前为止一切都那么好......然而实际发生的事情是,即使发布者发布时订户已经启动并运行,订阅者也不会收到所有消息(订阅者将收到100条消息,如果出版商将发送至少500条消息).似乎发布者发送的第一条消息不会发送给订阅者.
有任何想法吗?
提前谢谢,奥梅尔.
订阅者代码(在发布者之前发布)
int i=0;
zmq::context_t context (1);
zmq::socket_t subscriber (context, ZMQ_SUB);
subscriber.connect("tcp://localhost:5556");
subscriber.setsockopt(ZMQ_SUBSCRIBE, "", 0);
for (int update_nbr = 0; update_nbr < 100; update_nbr++)
{
zmq::message_t update;
subscriber.recv(&update);
i++;
std::cout<<"receiving :"<<i<<std::endl;
}
Run Code Online (Sandbox Code Playgroud)
发布商代码(在订阅者之后启动)
zmq::context_t context (1);
zmq::socket_t publisher (context, ZMQ_PUB);
publisher.bind("tcp://*:5556");
int i = 0;
for (int update_nbr = 0; update_nbr < 100; update_nbr++)
{
// Send message to all subscribers
zmq::message_t request (20);
time_t seconds;
seconds = time (NULL);
char update [20]="";
sprintf (update, "%ld", seconds);
memcpy …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法来检查Excel工作表当前是否处于活动状态(当前显示).我对同步方法感兴趣,而不是在事件中.
message = "hello %s , how are you %s, welcome %s"%("john","john","john")
Run Code Online (Sandbox Code Playgroud)
什么是避免指定"john"3次而是指定一个短语的最pythonic方法.
我正在使用 win32com.client 将数据写入 Excel 文件。这花费了太多时间(下面的代码模拟了我想要更新 Excel 的数据量,大约需要 2 秒)。
有没有一种方法可以在一次调用中更新多个单元格(具有不同的值),而不是一个一个地填充它们?或者也许使用更有效的不同方法?
我正在使用 python 2.7 和 Office 2010。
这是代码:
from win32com.client import Dispatch
xlsApp = Dispatch('Excel.Application')
xlsApp.Workbooks.Add()
xlsApp.Visible = True
workSheet = xlsApp.Worksheets(1)
for i in range(300):
for j in range(20):
workSheet.Cells(i+1,j+1).Value = (i+10000)*j
Run Code Online (Sandbox Code Playgroud) 我正在使用python请求发布请求.当附件参数有一些非ascii字符时会引发异常,在其他只存在ascii数据的情况下,一切都很好.
response = requests.post(url="https://api.mailgun.net/v2/%s/messages" % utils.config.mailDomain,
auth=("api", utils.config.mailApiKey),
data={
"from" : me,
"to" : recepients,
"subject" : subject,
"html" if html else "text" : message
},
files= [('attachment', codecs.open(f.decode('utf8'))) for f in attachments] if attachments and len(attachments) else []
)
Run Code Online (Sandbox Code Playgroud)
编辑: 使用utf8解码文件名后,我没有得到异常,但文件没有附加.我通过在其名称中附加仅包含ascii字符的文件来调试请求,并且请求标头请求构建是:
{'Content-Type': None, 'Content-Location': None, 'Content-Disposition': u'form-data; name="attachment"; filename="Hello.docx"'}
Run Code Online (Sandbox Code Playgroud)
这成功了,我收到附件的邮件.
但是,当使用带有希伯来字符的文件时,请求的标题是:
{'Content-Type': None, 'Content-Location': None, 'Content-Disposition': 'form-data; name="attachment"; filename*=utf-8\'\'%D7%91%D7%93%D7%99%D7%A7%D7%94.doc'}
Run Code Online (Sandbox Code Playgroud)
我收到邮件但没有附加文件.有任何想法吗?
我在 office 2010 中使用 python 和 excel,在那里没有问题。我使用 python 的 makepy 模块来绑定到 txcel com 对象。
但是,在另一台计算机上,我安装了 office 2013,当我启动 makepy 时,没有列出 excel 选项(与 office 2010 不同,其中 makepy 列出了“Microsoft Excel 14.0 对象库”)。
我在注册表中搜索了“Microsoft Excel 15.0 对象库”,它就在那里。我尝试使用 :makepy -d 'Microsoft Excel 15.0 Object Library'
但这没有用。
帮助将不胜感激。谢谢。
我有一个主要div包含一个表:
<div id="main_container"><table>
Run Code Online (Sandbox Code Playgroud)
你可以在http://jsfiddle.net/tF62u/看到完整的代码
如您所见,子表比div宽,但它(div)不会相应调整.
我在这里错过了哪个定义?
我有一个由jquery ready范围内的类选择器触发的click事件:
$(".testBtn").click(function()
{
alert("This Works");
});
Run Code Online (Sandbox Code Playgroud)
这适用于静态按钮,但这对于动态按钮不起作用,动态按钮在单击带有"addRowBtn"id的按钮时添加.我猜测它与事件被注册后创建按钮有关,但是新按钮仍然有'testBtn'类,所以它应该有效.知道我做错了什么以及如何将动态按钮注册到类选择器点击事件?
这是整个代码,您可以复制并粘贴到html中,单击"添加按钮"并尝试单击添加的按钮.你会发现什么都没发生.
<html>
<head>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
<script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js'></script>
<script>
$(function()
{
$(".addRowBtn").click(function()
{
$("#mainTable tr:last").after("<tr><td><button class='testBtn'>NotWorking</button></td></tr>");
});
$(".testBtn").click(function()
{
alert("This Works");
});
});
</script>
</head>
<body>
<table id="mainTable">
<button class="addRowBtn">Add button</button>
<tr><th>Testing</th></tr>
<tr><td><button class='testBtn'>Working</button></td></tr>
</table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我有兴趣将输入字段编码为gmail的撰写屏幕中的"to"字段.这意味着每个数据都使用一个框架封装,该框架具有"x"选项以将其删除.

这是我的流程:主页面位于'/ main'网址,因此当用户访问该页面时,我的Web服务器返回一个静态html:
<!DOCTYPE html>
<html ng-app="sam">
<head>
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
</head>
<body>
<div ng-controller="BuildingsController as buildings">
<button ng-click="RefreshBuildings()">Refresh</button>
<h1>{{buildings.elements.length}}</h1>
<table>
<tr>
<th>id</th>
<th>name</th>
<th>last_updated</th>
<th>based_on_file</th>
</tr>
<tr ng-repeat="element in buildings.elements | orderBy:'-id'">
<td>{{element.id}}</td>
<td><a ng-href="/getTenants?buildingId={{element.id}}">{{element.name}}</a></td>
<td>{{element.last_updated | date}}</td>
<td>{{element.based_on_file}}</td>
<td><button ng-click="buildings.UpdateDataBase(element.id)">Refresh</button></td>
</tr>
</table>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.13/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="app.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是js文件:
(function(){
var app = angular.module('sam', []);
app.controller('BuildingsController', ['$http','$log', function($http, $log){
//Update scope pramaters
this.RefreshGui = function(elements){
this.elements = elements
};
//call server to …Run Code Online (Sandbox Code Playgroud) typedef std::map<std::string,int> string2intMap;
typedef string2intMap arrOfMaps[3] ;
//map : string --> array of maps of <std::string,int>
std::map<std::string,arrOfMaps> tryingStuff;
//map : string --> int
string2intMap s;
s["key"]= 100;
tryingStuff["hello"][0] = s;
Run Code Online (Sandbox Code Playgroud)
上面的代码没有编译,有问题的行是:tryingStuff ["hello"] [0] = s;
这是编译器大喊:
c:\program files (x86)\microsoft visual studio 10.0\vc\include\map(215): error C2440: '<function-style-cast>' : cannot convert from 'int' to 'std::map<_Kty,_Ty> [3]'
2> with
2> [
2> _Kty=std::string,
2> _Ty=int
2> ]
2> There are no conversions to array types, although there are conversions to references or pointers to …Run Code Online (Sandbox Code Playgroud)