在服務(wù)器上的代碼如下
from __future__ import unicode_literals
from flask_restful import Api
from flask import Flask,request
import time
import datetime
#########product==========
import json
#####放在11.46庫
import TextDropRepeat as tdr
import pymongo
import numpy as np
from numpy import array
app = Flask(__name__)
app.debug = True
app.config.update(RESTFUL_JSON=dict(ensure_ascii=False))
api = Api(app)
TODOS = {
'conhashGroup': {'task': []},
'publishtime': {'task':[]},
'conhashGroupA': {'task': []},
'conhashGroupB': {'task': []},
'conhashGroupC': {'task': []},
'conhashGroupD': {'task': []},
}
from flask_restful import reqparse
parser = reqparse.RequestParser()
parser.add_argument('task')
@app.route('/')
def hello_world():
return 'hello world'
@app.route('/drop_TextRepeat/', methods=['POST'])
def add_task():
print (TODOS)
nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
pastTime = (datetime.datetime.now()-datetime.timedelta(days=5)).strftime('%Y-%m-%d %H:%M:%S')
time_start=time.time()
print ('開始獲取數(shù)據(jù)')
####獲取數(shù)據(jù)
try:
data1 = request.form.get('data')
print (1)
except:
data1 = request.data
print (2)
#print (data1)
print ('獲取數(shù)據(jù)成功')
for line in data1.split('\n'):
if 'DRETITLE' in line:
title = line.split('#DRETITLE')[1].strip()
if 'PUBLISHDATE' in line:
publishdate = line.replace('=','').replace('"','').split('PUBLISHDATE')[1].strip().replace("'","")
print (publishdate)
print (title)
###轉(zhuǎn)換64位hash
ConHash = tdr.simhash(title)
####切割4*16hash
ConHashA = str(ConHash)[0:16]
ConHashB = str(ConHash)[16:32]
ConHashC = str(ConHash)[32:48]
ConHashD = str(ConHash)[48:]
if ConHashA in TODOS['conhashGroupA']['task']:
print (3)
TODOS['conhashGroup']['task'].append(ConHash)
TODOS['publishtime']['task'].append(publishdate)
TODOS['conhashGroupA']['task'].append(ConHashA)
TODOS['conhashGroupB']['task'].append(ConHashB)
TODOS['conhashGroupC']['task'].append(ConHashC)
TODOS['conhashGroupD']['task'].append(ConHashD)
index = np.where((pastTime<=array(TODOS['publishtime']['task'])) & (array(TODOS['publishtime']['task'])<nowTime ))[0].tolist()
TODOS['publishtime']['task'] = np.array(TODOS['publishtime']['task'])[index].tolist()
TODOS['conhashGroup']['task'] = np.array(TODOS['conhashGroup']['task'])[index].tolist()
TODOS['conhashGroupA']['task'] = np.array(TODOS['conhashGroupA']['task'])[index].tolist()
TODOS['conhashGroupB']['task'] = np.array(TODOS['conhashGroupB']['task'])[index].tolist()
TODOS['conhashGroupC']['task'] = np.array(TODOS['conhashGroupC']['task'])[index].tolist()
TODOS['conhashGroupD']['task'] = np.array(TODOS['conhashGroupD']['task'])[index].tolist()
time_end=time.time()
print ('totally cost',time_end-time_start)
return 'ok'
if __name__ == '__main__':
app.run(host = '0.0.0.0')
uwsgi配置文件如下
[uwsgi]
socket=/tmp/uwsgi.sock
mount=/myapp=/home/nlp/pyfoot/TD/DropText.py
manage-script-name=true
master=true
processes=4
threads=2
stats=127.0.0.1:9191
callable=app
daemonize = /home/nlp/pyfoot/TD/DropText.log
nginx配置如下
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
server {
listen 8000;
access_log /home/nlp/pyfoot/TD/DR.log main;
server_name 172.22.11.46;
location /myapp {
root /myapp;
include uwsgi_params;
#uwsgi_param SCRIPT_NAME/myapp;
uwsgi_pass unix:/tmp/uwsgi.sock;
}
}
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
}
當(dāng)我在本地電腦瀏覽器訪問服務(wù)器時(shí)如下,正常顯示helloworld
但是通過py腳本post傳輸數(shù)據(jù)時(shí)就報(bào)錯(cuò),代碼如下
import requests
content = {'data':'#DRETITLE 李克強(qiáng)總理訪歐成果惠及企業(yè)及民眾\n#DREFIELD PUBLISHDATE="2018-07-28 04:42:55"'}
r = requests.post('http://172.22.11.46:8000/myapp/drop_TextRepeat/', data=content)
報(bào)錯(cuò)信息如下
python返回值如下
r.text
Out[29]: '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">\n<title>404 Not Found</title>\n<h1>Not Found</h1>\n<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>\n'
請問大佬,這個(gè)是什么情況,瀏覽器中可以訪問成功,說明配置沒啥問題,但是換post接口就報(bào)錯(cuò),小弟一直想不明白,還請大佬解惑
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團(tuán)創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機(jī)構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團(tuán),成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。