您好,我创建了一个项目,其文件夹结构如下:
为什么在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
在
Practise
文件夹中添加了一个空的__init__.py
文件,以便将其视为一个包或者做一个相对的导入,比如
而不是
相关问题 更多 >
编程相关推荐