Tag: python requests

Python请求:从Nodejs HTTP服务器请求突然缓慢

我有一个NodeJS HTTP服务器,显示一个JSON文件,每秒更新多次。 样本数据: { "MainText": [{ "field1": "text", "field2": "text", "field3": 1234 }, { "field1": "text", "field2": "text", "field3": 1234 }, { "field1": "text", "field2": "text", "field3": 1234 } ] } 通常在一段时间之后,这个JSON中这样的条目的数量增长到约200k或更多。 我必须将整个JSON导入一个pandas数据框,我正在使用以下方法: df = pd.DataFrame(json.loads(requests.get(url).text)) 通常这大概需要0.3秒。 但是对于我来说没有任何理由,在几个请求之后,它开始花费接近4秒(几乎)相同的固定大小的JSON。 在发出请求时,CPU或RAM的使用量没有变化。 如果我重新启动NodeJS服务器,则问题会暂时解决,但稍后会回来。 我是否需要closures与HTTP服务器的连接? 我希望180K行的文本是不是太多的请求从服务器快速获取? 我应该寻找一种将JSON数据加载到pandas数据框的更有效的方法吗?

已解决 – 客户端错误:消息中的坏对象:bson长度与我们find的不匹配

我正在将数据发布到利用Mongoose和MongoDB的Node / Express API上。 在尝试使用此模式进行批量插入时,数据和处理程序: // Mongoose schema var NotificationSchema = new Schema({ uuid: { type: String, required: true, index: true }, message: { type: String, required: true }, url: { type: String, required: true } }); // sample data [ { 'uuid': '34e1ffef49ad4001bb9231c21bdb3be7', 'url': '/polls/4666386cb92348af93417e9abb9ce880/forecast/', 'message': '@btaylor has shared a poll with you' }, […]

将响应中的JSON数据传递给Django中的请求

我有一个Django(1.8.3)的观点: 对服务器A(jetty)发出GET请求,该请求返回响应正文中的JSON数据。 然后, 对服务器B(node.js)进行POST,将请求正文中从服务器A接收的JSON数据传递给服务器B. JSON数据的结构如下所示: { name: "foo", details: { "date": "today", "isCool": "no", }, stuff: [ { "id": "1234", "rating": "5", }, { "id": "5678", "rating": "1", }, ] } 但我无法弄清楚如何从服务器A的响应到服务器B在我的Django视图的请求中获取JSON。 如果我这样做: jetty_response = requests.request(method='GET', url=jetty_url) node_response = requests.request(method="POST", url=node_url, data=jetty_response.json()) 我得到服务器B中的JSON对象,但它看起来像这样: { name: "foo", details: [ "date", "isCool"], stuff: [ "id", "rating", "id", […]

通过python websocket客户端传递cookie

我正在使用websocket客户端连接到一个node.js服务器(这是我的websocket服务器),我已经能够通过从python到node.js的websockets成功发送消息。 我的python客户端使用请求模块login到一个网站,并收集cookie(由于成功login从服务器传递)。 我希望这些cookie作为websocket-client的一部分被传递,如代码所示。 我从login中获得以下cookie: (Pdb) requests.utils.dict_from_cookiejar(client.cookies) {'csrftoken': 'DhSf0z9Ouu5f1SbfGWBg5BuBe1UuJMLr', 'sessionid': 'pu6ig4z4mtq5k8rvm6kuv8g3fdegs47d'} 如何在创buildwebsocket时发送该cookie? ws = websocket.WebSocketApp("ws://localhost:8080/", on_message = on_message, on_error = on_error, on_close = on_close, # cookie = ? what goes here ? )

请求库不正确地通过代理来引导HTTP请求

我知道如何使用requests ,但由于某种原因,我没有成功地让代理工作。 我正在提出以下要求: r = requests.get('http://whatismyip.com', proxies={'http': 'http://148.236.5.92:8080'}) 我得到以下内容: requests.exceptions.ConnectionError: [Errno 10060] A connection attempt failed b ecause the connected party did not properly respond after a period of time, or e stablished connection failed because connected host has failed to respond 然而,我知道代理工程,因为使用节点: request.get({uri: 'http://www.whatismyip.com', proxy: 'http://148.236.5.92:8080'}, function (err, response, body) {var $ = cheerio.load(body); […]