之前我使用httplib模块在请求中添加标头.现在我正在尝试与requests模块相同的事情.
这是我正在使用的python请求模块:http: //pypi.python.org/pypi/requests
如何添加标题,request.post并request.get说我必须foobar在标题中的每个请求中添加密钥.
我正在使用本教程。我需要向新连接的用户发送旧消息。我怎样才能做到这一点?我的意思是新用户应该能够看到旧消息。
对于我的应用程序,我不需要将数据存储在数据库中。一旦服务器关闭,则应删除数据。但是服务器在每个会话上运行多长时间客户端应该收到以前的消息
我试过了
const history = []
//Telling Express+Socket.io App To Listen To Port
io.sockets.on("connection",function(socket){
socket.emit("Start_Chat");
//On Event Registar_Name
socket.on("Register_Name",function(data){
console.log(data)
io.sockets.emit("r_name","<strong>"+data+"</strong> Has Joined The Chat");
//Now Listening To A Chat Message
socket.on("Send_msg",function(data){
history.push(data)
console.log(history)
io.sockets.emit("msg",data);
//Now Listening To A Chat Message
})
})
})
Run Code Online (Sandbox Code Playgroud)
但是我怎么能说新客户何时输入发送历史数据?
更新:我尝试了以下但它总是发送历史
const history = []
const client = []
//Telling Express+Socket.io App To Listen To Port
io.sockets.on("connection",function(socket){
client.push({id : socket.client.id})
console.log(client)
socket.emit("Start_Chat");
//On Event Registar_Name
socket.on("Register_Name",function(data){
console.log(data)
io.sockets.emit("r_name","<strong>"+data+"</strong> Has Joined The Chat"); …Run Code Online (Sandbox Code Playgroud) 我是用乳胶写的。我是新手,需要一些帮助。
我需要添加数字。我可以用下面的代码来做到这一点
\begin{figure}[h]
\includegraphics[width = 15cm]{figures/mlpStrSingle}
\caption{MLP neural network for one single output node}
\label{fig:mlp}
\end{figure}
Run Code Online (Sandbox Code Playgroud)
如果我使用它,该图将转到下一页。我需要在文本之后立即使用它。那么下一个文本应该开始。我怎样才能做到这一点?
提前致谢。
我正在尝试观看我的 mongodb。每当发生更改时,我都想应用一个操作。这是我尝试过的
var mongoose = require('mongoose');
//mongoose.connect('mongodb://localhost/test');
mongoose.Promise = global.Promise
mongoose.connect('mongodb://localhost:27017')
mongoose.connection.createCollection('people');
const Person = mongoose.model('Person', new mongoose.Schema({ name: String }));
Person.watch().
on('change', data => console.log(new Date(), data));
console.log(new Date(), 'Inserting doc');
Person.create({ name: 'john doe' });
console.log(new Date(), 'Inserted doc');
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误
node_modules/mongodb/lib/utils.js:132 抛出错误;^
MongoError: $changeStream 可能无法在内部管理数据库上打开
我怎样才能解决这个问题 ?
我正在尝试使用 reactjs 从前端上传文件。后端使用 Flask python。我收到响应代码 400。我做错了什么?
前端 :
<input type="file" name="file" onChange={this.onChangeFile}/>
<button onClick={this.uploadFile}>
Upload
</Button>
uploadFile(e){
e.preventDefault()
let f = this.state.fileToBeSent
let f_name = this.state.fileToBeSent.name
console.log(f_name)
let fileReader = new FileReader()
fileReader.readAsDataURL(f)
fileReader.onload = (e) => {
let toPost = {
'file_name' : f_name,
'file_data': e.target.result
}
console.log(toPost)
return axios.post('/api/upload', toPost)
.then(res => console.log(res))
.catch(err => console.warn(err))
}
}
Run Code Online (Sandbox Code Playgroud)
并在后端:
@app.route('/api/upload', methods = ['POST'])
def upload_file():
file = request.files['file']
print(file)
return "done"
Run Code Online (Sandbox Code Playgroud) 我正在尝试将 Postgresql 与 python 一起使用。我使用了以下 docker 来编写文件。
version: '3.1'
services:
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: admin_123
POSTGRES_USER: admin
adminer:
image: adminer
restart: always
ports:
- 8080:8080
Run Code Online (Sandbox Code Playgroud)
使用以下代码,我尝试连接数据库。
conn = psycopg2.connect(
database = "db_test",
user ="admin",
password = "admin_123",
host = "db"
)
Run Code Online (Sandbox Code Playgroud)
但我收到此错误。
OperationalError:无法将主机名“db”转换为地址:提供了节点名或服务名,或未知
我做错了什么?
我有一个txt数据。它看起来如下
time pos
0.02 1
0.1 2
...
Run Code Online (Sandbox Code Playgroud)
等等。所以每一行都用空格隔开。我需要将其转换为 CSV 文件。喜欢
time,pos
0.02,1
0.1,2
0.15,3
Run Code Online (Sandbox Code Playgroud)
我怎样才能用 python 做到这一点?这是我尝试过的
time = []
pos = []
def get_data(filename):
with open(filename, 'r') as csvfile:
csvFileReader = csv.reader(csvfile)
next(csvFileReader)
for row in csvFileReader:
time.append((row[0].split(' ')[0]))
pos.append((row[1]))
return
Run Code Online (Sandbox Code Playgroud) 如何检查某个文件夹中是否存在任何文件?我知道如何检查 A 文件。如下
a = os.path.exists("text.txt")
if a:
print("file is there")
else:
print("not found")
Run Code Online (Sandbox Code Playgroud)
提前致谢