Apache2 웹 서버에서 Python 기반 Discord 봇을 실행하는 데 문제가 있습니다. 저는 discord.py API 래퍼를 사용하고 있으며 pyenv를 사용하여 Python 3.5.1을 설치했습니다.
이게 내 코드야
#!/usr/bin/env python
import discord
import asyncio
import requests.packages.urllib3
requests.packages.urllib3.disable_warnings()
client = discord.Client()
@client.event
async def on_message(message):
if message.content.startswith('!logi'):
Cmd = message.content.lstrip('!logi ')
Cmd = Cmd.split()
From = Cmd[0]
To = Cmd[2]
await client.send_message(message.channel, 'starting search for %s to %s' % (From, To))
To_High=['Hydrogen Fuel','Consumer Technology','Clothing','Domestic Appliances','Animal Meat','Coffee','Fish','Fruit','Grain','Tea','Synthetic Meat','Food Cartridges','Superconductors','Heliostatic Furnaces','Basic Medicines','Paladium','Silver','Gold','Indium','Lithium','Tantalum','Titanium','Uranium','Gallium','Lepidolite','Cobalt','Computer Components','Non-Lethal Weapons']
From_High=['Pesticides','Agricultural Medicines','Consumer Technology','Synthetic Meat','Progenitor Cells','Advanced Catalysers','Animal Monitors','Awuaponic Systems','Auto Fabricators','Bio Reducing Lichen','H.E. Suits','Resonating Separators','Robotics','Terrain Enrichment Systems','Non-Lethal Weapons','Biowaste','Scrap']
To_Industrial=['Hydrogen Fuel','Consumer Technology','Clothing','Domestic Appliances','Animal Meat','Coffee','Fish','Fruit','Grain','Tea','Synthetic Meat','Food Cartridges','Algae','Polymers','Semiconductors','Superconductors','Basic Medicines','Progenitor Cells','Gold','Copper','Aluminium','Beryllium','Indium','Lithium','Tantalum','Titanium','Uranium','Gallium','Auto Fabricators','H.E. Suits','Robotics','Leather','Natural Fabrics','Synthetic Fabrics','Non-Lehal Weapons']
From_Industrial=['Clothing','Domestic Appliances','Food Cartridges','Marine Supplies','Crop Harvesters','Mineral Extractors','Heliostatic Furnaces','Basic Medicines','Computer Components','Biowaste','Scrap']
To_Agri=['Pesticides','Agricultural Medicines','Hydrogen Fuel','Consumer Technology','Clothing','Domestic Appliances','Animal Meat','Coffee','Fish','Fruit','Grain','Tea','Marine Supplies','Crop Harvesters','Basic Medicines','Progenitor Cells','Animal Monitors','Aquaponic Systems','Terrain Enrichment Systems','Non-Lethal Weapons']
From_Agri=['Mineral Oil','Animal Meat','Coffee','Fish','Fruit','Grain','Tea','Algae','Leather','Natural Fabrics','Biowaste']
To_Refinery=['Hydrogen Fuel','Mineral Oil','Consumer Technology','Clothing','Domestic Appliances','Animal Meat','Coffee','Fish','Fruit','Grain','Tea','Synthetic Meat','Food Cartridges','Heliostatic Furnaces','Basic Medicines','Progenitor Cells','Gallite','Indite','Uranimite','Bertrandite','Coltan','Rutile','Advanced Catalysers','Resonating Separators','Non-Lethal Weapons','Scrap']
From_Refinery=['Hydrogen Fuel','Explosives','Polymers','Semiconductors','Superconductors','Copper','Aluminium','Beryllium','Indium','Lithium','Tantalum','Titanium','Uranium','Gallium','Lepidolite','Cobalt','Synthetic Fabrics','Biowaste']
To_Extraction=['Hydrogen Fuel','Explosives','Consumer Technology','Clothing','Domestic Appliances','Animal Meat','Coffee','Fish','Fruit','Grain','Tea','Synthetic Meat','Food Cartridges','Mineral Extractors','Basic Medicines','Bio Reducing Lichen','H.E. Suits','Non-Letha; Weapons']
From_Extraction=['Paladium','Silver','Gold','Gallite','Indite','Uranimite','Bertrandite','Coltan','Rutile','Biowaste']
if From == 'High-Tech':
Cmp1 = From_High
if From == 'Industrial':
Cmp1 = From_Industrial
if From == 'Agricultural':
Cmp1 = From_Agri
if From == 'Refinery':
Cmp1 = From_Refinery
if From == 'Extraction':
Cmp1 = From_Extraction
if To == 'High-Tech':
Cmp2 = To_High
if To == 'Industrial':
Cmp2 = To_Industrial
if To == 'Agricultural':
Cmp2 = To_Agri
if To == 'Refinery':
Cmp2 = To_Refinery
if To == 'Extraction':
Cmp2 = To_Extraction
for x in range(len(Cmp1)):
for y in range(len(Cmp2)):
if Cmp1[x] == Cmp2[y]:
await client.send_message(message.channel, Cmp1[x])
await client.send_message(message.channel, 'search finished')
if message.content.startswith('!fact'):
print ('received command')
await client.send_message(message.channel, 'Welcome to Factual-Bot v0.1.0! For all your trading needs!')
await client.send_message(message.channel, 'Use the !logi command to find profitable trade routes')
await client.send_message(message.channel, 'The syntax is !logi [economy1] to [economy2]')
await client.send_message(message.channel, 'The following economies are supported')
await client.send_message(message.channel, 'High-Tech')
await client.send_message(message.channel, 'Industrial')
await client.send_message(message.channel, 'Agricultural')
await client.send_message(message.channel, 'Refinery')
await client.send_message(message.channel, 'Extraction')
print ('transmission sent')
client.run('MTgyODU3ODMyOTM5NTIwMDAz.Ch9bIA.sse2NajDnizDGVxK6BqNIpPg_ng')
실행해보니 잘 나오네요
python factual-bot.py
그러나 그것은 껍질을 차지합니다. 적절한 "cgi-bin" 스크립트 확장자를 설정하여 다른 Python 스크립트를 실행하는 웹 서버가 이미 있고 모든 스크립트에 대한 권한을 755로 설정했습니다. 그럼에도 불구하고 이것은 apache2에서 발생하는 오류입니다.
[Fri May 20 00:15:37 2016] [error] [client 192.168.0.4] Premature end of script headers: factual-bot.py
File "/usr/lib/cgi-bin/factual-bot.py", line 12
async def on_message(message):
^
SyntaxError: invalid syntax
[Fri May 20 00:15:39 2016] [error] [client 192.168.0.4] Premature end of script headers: factual-bot.py
답변1
좀 더 조사해본 결과 그런 것 같아요화면내 목적에 더 잘 맞을 텐데