ModuleNotFoundError:尽管此文件夹存在,但没有名为“Practice”的模块

2024-09-30 01:27:12 发布

您现在位置:Python中文网/ 问答频道 /正文

您好,我创建了一个项目,其文件夹结构如下:

Folder Structure in VS Code

为什么在VS代码中运行postpiautomation.py时出现以下错误

[Running] python -u "c:\Users\Umang Bhatia\Documents\Udemy\BackEndAutomation\Practise\postAPIAutomation.py"
Traceback (most recent call last):
  File "c:\Users\Umang Bhatia\Documents\Udemy\BackEndAutomation\Practise\postAPIAutomation.py", line 4, in <module>
    from Practise.postPayload import *
ModuleNotFoundError: No module named 'Practise'

postpaiutomation.py的代码如下:

import requests
import json
from jsonpath import jsonpath
from Practise.postPayload import *

#Adding a book
add_book_res = requests.post(
    url= 'http://216.10.245.166/Library/Addbook.php',
    json= add_book_payload('Alchemist', 'gfgerg', 'Paolo Cohelo'),
    headers= {'Content-Type': 'application/json'}
)

print(add_book_res.status_code)
res_json = add_book_res.json()
res_book_id = res_json['ID']

#Deleting a book

delete_book_payload = requests.post(
    url = 'http://216.10.245.166/Library/DeleteBook.php',
    json= delete_book_payload(res_book_id),
    headers= {'Content-Type': 'application/json'}
)

print(delete_book_payload.status_code)

postPayload.py的代码如下:

def add_book_payload(book_name,isbn,author):
    input_json = {
        "name": book_name,
        "isbn": isbn,
        "aisle":"227",
        "author": author
        }

    return input_json

def delete_book_payload(book_id):
    input_json = {
        "ID" : book_id
        } 

    return input_json

Tags: 代码frompyimportaddidjsoninput

热门问题