Apache2 WebサーバーでDiscord.py、pyenv python 3.5.1スクリプトを実行します。

Apache2 WebサーバーでDiscord.py、pyenv python 3.5.1スクリプトを実行します。

Apache2 Webサーバーで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スクリプトを実行しているWebサーバーがすでに存在し、すべてのスクリプトに対する権限を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

もう少し調べた結果、そうだと思います。画面私の目的にもっと合います。

おすすめ記事