Я попытался включить скрипт Python в каталог проекта.Я хочу просто запустить getoffense.py (в рамках проекта1), и 3 сценария будут выполняться косвенно при выполнении getoffense.py.Этими тремя сценариями являются SampleUtilities.py, RestApiClient.py и config.py.these 3 сценария находятся в разделе «модули»
Когда я запускаю эту программу отдельно от django, она работает отлично, однако, когда я использую модульпуть сервер выдает мне ошибку об этом.
Я объяснил вам как можно лучше, помогите, поскольку я новичок в Python и Django.это структура моего проекта
C:.
├───.idea
└───project1
├───modules
├───Templates
└───__pycache__
Я хочу запустить эти внешние скрипты Python и показать результат в html-файле.
Это мой getofense.py
import json
import os
import sys
import importlib
sys.path.append(os.path.realpath('/modules'))
client_module = importlib.import_module('/modules/RestApiClient')
SampleUtilities = importlib.import_module('/modules/SampleUtilities')
def main():
# First we have to create our client
client = client_module.RestApiClient(version='9.0')
# -------------------------------------------------------------------------
# Basic 'GET'
# In this example we'll be using the GET endpoint of siem/offenses without
# any parameters. This will print absolutely everything it can find, every
# parameter of every offense.
# Send in the request
SampleUtilities.pretty_print_request(client, 'siem/offenses', 'GET')
response = client.call_api('siem/offenses', 'GET')
# Check if the success code was returned to ensure the call to the API was
# successful.
if (response.code != 200):
print('Failed to retrieve the list of offenses')
SampleUtilities.pretty_print_response(response)
sys.exit(1)
# Since the previous call had no parameters and response has a lot of text,
# we'll just print out the number of offenses
response_body = json.loads(response.read().decode('utf-8'))
print('Number of offenses retrieved: ' + str(len(response_body)))
# ------------------------------------------------------------------------
# Setting a variable for all the fields that are to be displayed
fields = '''id%2Cstatus%2Cdescription%2Coffense_type%2Coffense_source%2Cmagnitude%2Csource_network%2Cdestination_networks%2Cassigned_to'''
# Send in the request
SampleUtilities.pretty_print_request(client, 'siem/offenses?fields='+fields, 'GET')
response = client.call_api('siem/offenses?fields=' +fields, 'GET')
# Once again, check the response code
if (response.code != 200):
print('Failed to retrieve list of offenses')
SampleUtilities.pretty_print_response(response)
sys.exit(1)
# This time we will print out the data itself
#SampleUtilities.pretty_print_response(response)
response_body = json.loads(response.read().decode('utf-8'))
print(response_body)
print(type(response_body))
for i in response_body:
print(i)
print("")
for j in response_body:
print(j['id'])
print(j['status'])
print(j['description'])
if __name__ == "__main__":
main()
это сообщение об ошибке
File "C:\celery\project1\project1\urls.py", line 18, in <module>
from . import views
File "C:\celery\project1\project1\views.py", line 2, in <module>
from . import getoffenses
File "C:\celery\project1\project1\getoffenses.py", line 25, in <module>
SampleUtilities = importlib.import_module('SampleUtilities')
File "C:\Users\kiran.tanweer\Envs\celery\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'SampleUtilities'