,而且我不明白为什么并且在网上找不到任何东西。我该如何避免这种warninig?
也是这是一个Uni项目,所以我故意没有考虑安全问题等。重点是通过API存储键值对。
我的VUE组件:
<template>
<h3>Input Data Reading</h3>
<div class="buttonWrapper">
<button class="storeData" id="storeInputData" @click="readInputFile">
Read and Store Data
</button>
</div>
<div v-if="fetchedResponse" class="response">
{{ fetchedResponse }}
</div>
</template>
<script>
import Papa from 'papaparse'
import { mapActions } from 'vuex';
export default {
name: 'ReadInputData',
props: {
msg: String
},
data() {
return {
fetchedResponse: ''
}
},
methods: {
...mapActions(['updateKeys']),
readInputFile() {
Papa.parse('http://127.0.0.1.nip.io/storage/api/download/inputfile', {
header: true,
download: true,
worker: true,
step: (row) => {
this.storeData(row.data);
},
complete: () => {
console.log('Successfully stored file.');
},
error: (e) => {
console.error(`Error parsing the file: ${e}`)
}
});
},
storeData(data) {
var key = data['id'];
var value = data['title'];
this.updateKeys(key)
fetch('http://127.0.0.1.nip.io/storage/api/insert/', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
key: key,
value: value
})
})
.then(response => response.json())
.then(message => this.fetchedResponse = message)
.catch(e => console.error(e));
}
}
}
</script>
<style scoped>
</style>
import asyncio
from flask import Flask, Response, jsonify, logging as flaskLogging, request
from flask_cors import CORS
import logging
from storage_handler import StorageHandler
logging.basicConfig(level=logging.DEBUG, format=f'%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s')
if __name__ == '__main__':
app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "*"}}, expose_headers=['Content-Range'])
event_loop = asyncio.get_event_loop()
logger = flaskLogging.create_logger(app)
storage_handler = StorageHandler(logger, event_loop)
@app.route('/download/inputfile', methods=['GET'])
def serve_input_file():
while event_loop.is_running():
asyncio.sleep(0.01)
def readCSVfile():
with open('./input_file/Imdb_Movie_Dataset.csv', 'r') as f:
for line in f:
yield line
response = Response(readCSVfile(), content_type='text/csv')
return response
@app.route('/insert/', methods=['POST'])
def insert_pair():
while event_loop.is_running():
asyncio.sleep(0.01)
pair = request.get_json()
key = pair.get('key')
value = pair.get('value')
request_str = f'store {key if key else "EMPTY_KEY_STR_PASSED"} {value if value else "EMPTY_VALUE_PASSED"}'
response = event_loop.run_until_complete(storage_handler.request_to_bucket(request_str))
return jsonify(response.decode())
app.run(host='0.0.0.0', port=5000)
您的CSV文件如何? 听起来像一个以上的标头列共享同名。 标题为(CSV中的第0行),如果定义标头:Papaparseconfig.
中的true。 当标题:true设置为papaparse时,header列名称必须是唯一的。 否则,它们会自动重命名,否则无法构建JSON对象。 这将导致这样的事情:
因此,如果您的CSV看起来像这样: “标头Col 1”,“标头Col 2”,“标头Col 1”
基本上,标题列名称将用于构建JSON对象。因此,它不能重复。必须是所有标头列的唯一名称。
一个简单的解决方案可能是设置标头:如果您不需要的话,则可以是false。 如果您需要拥有hgeaders:正确确保列名是唯一的或忽略了警告。 Hekps.