带有Django的ebay python SDK-通过views.py调用addietm函数时找不到配置文件,否则可以正常工作

问题描述

我正在构建一个django项目,在我的views.py中,我试图从同一目录中的另一个.py文件调用一个函数,从而对ebay进行api调用。当我在.py文件中运行该函数时,它工作正常,但是当我从views.py调用它时,出现此错误

'config file ebay.yaml not found. Set config_file=None for use without YAML config.'

我不明白为什么只有在从views.py调用它时才会发生这种情况? ebay.yaml文件与这两个文件位于同一目录中。

views.py

from django.http import HttpResponse
from django.shortcuts import render
import sys
from djangonautic.forms import HomeForm
import _sqlite3
import os.path
from djangonautic import additem #this is the file that has the function

def homepage(request):

    if request.method == "POST":

        form = HomeForm(request.POST)
        if form.is_valid():
            print("Form was valid")
            text = form.cleaned_data['post']
            config_for_ebay = 'ebay.yaml' #config file to make api call
            resp_object = additem.make_api_call(text,config_file=config_for_ebay)
            args = {'form': form,'text': text}
            context = {'title': resp_object}
            return render(request,"script_run.html",context=context)
    else:
        print("ewe")
        form = HomeForm()
        return render(request,"homepage.html",{'form': form,'text': 'bla'})

additem.py

from ebaysdk.Trading import Connection

from djangonautic import api_formatting_for_raw_html
from djangonautic import get_categories
#var_pics = {'Color': [x[1] for x in variations]}

def make_api_call(url,config_file):
    '''Makes the api call to add product,also calls other functions to import the product in the url'''
    (title_fr,listing_has_variations,main_product_images,price_value,variation_node,variationSpecificsSet,variationSpecificName,variationSpecificPictureSet) = api_formatting_for_raw_html.format_api_call(url)
    cateid = get_categories.get_suggested_categories(url,config_file = config_file)[1]
...
...

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)