预测:为什么我可以用curl而不是python发布帖子请求?

时间:2016-12-23 00:06:24

标签: python curl localhost put predictionio

我正在尝试将数据导入到predictio中。我可以用curl罚款单独发送每个事件:

curl -i -X POST http://localhost:7070/events.json?accessKey=285285285 \
-H "Content-Type: application/json" \
-d '{
  "event" : "buy",
  "entityType" : "user",
  "entityId" : "u1",
  "targetEntityType" : "item",
  "targetEntityId" : "i2",
  "eventTime" : "2014-11-10T12:34:56.123-08:00"
}'
HTTP/1.1 201 Created
Server: spray-can/1.3.3
Date: Fri, 23 Dec 2016 00:02:32 GMT
Content-Type: application/json; charset=UTF-8
Content-Length: 46

{"eventId":"48a00669b43f4655b9e64762721b859d"}

然而,当我尝试使用Python自动执行此操作时,我收到错误。这是Python脚本:

import predictionio
client = predictionio.EventClient(
    access_key='285285285',
    url='http://localhost:7070',
    threads=5,
    qsize=500)

client.create_event(
                event="rate",
                entity_type="user",
                entity_id="Bob",
                target_entity_type="item",
                target_entity_id="Fred",
                properties= { "rating" : 5.0 }
            )  


给出以下错误..

predictionio.NotCreatedError: Exception happened: [Errno 10061] No connection could be made because the target machine a
ctively refused it for request POST /events.json?accessKey=285285285 {'event': 'rate', 'eventTime': '2016-12-22T23:13:24
.210+0000', 'entityType': 'user', 'targetEntityId': 'Fred', 'properties': {'rating': 5.0}, 'entityId': 'Bob', 'targetEnt
ityType': 'item'} /events.json?accessKey=285285285?event=rate&eventTime=2016-12-22T23%3A13%3A24.210%2B0000&entityType=us
er&targetEntityId=Fred&properties=%7B%27rating%27%3A+5.0%7D&entityId=Bob&targetEntityType=item

这个错误意味着什么,我可以做些什么来纠正它。提前致谢

0 个答案:

没有答案