简体   繁体   English

在生产服务器上导入数据时出错-在本地工作正常

[英]Error importing data on production server- locally works fine

I'm trying to import this CSV file. 我正在尝试导入此CSV文件。 It works perfectly on my local setup on django. 它在django上的本地设置上完美运行。 However- it won't import on my actual server/production version. 但是-它不会导入我的实际服务器/生产版本中。

I am using SQLite (locally), and Postgres on the server. 我在服务器上使用SQLite(本地)和Postgres。 But I don't see any settings that would affect it. 但是我看不到任何会影响它的设置。 Any suggestions? 有什么建议么?

My import file: 我的导入文件:

import sys, os
import django

sys.path.append('/srv/apps/stashdDB/code')
os.environ['DJANGO_SETTINGS_MODULE'] = 'stashdDB.settings'

django.setup()

import stashd.models as m




import csv

l = list(csv.reader(open('test_data.csv', encoding='utf-8', errors='ignore')))

Gender_CHOICES = {
    'Male': 1,
    'Female': 2,
    'Unisex': 3,
}

Stock_CHOICES = {
    'in stock': 1,
    'low stock': 2,
    'out of stock': 3,
    'discountinued': 4
}

for i in l[1:]:
        cat = m.Category.objects.get_or_create(category_name = i[4])[0]
        prod = m.Product(
            name = i[0],
            link = i[1],
            description = i[6],
            brand = i[7],
            gender = Gender_CHOICES[i[8]] if i[8] in Gender_CHOICES else 3,
            store = m.Store.objects.get_or_create(store_name = i[2])[0]
            )
        prod.save()
        var = m.Variation(
            product = prod,
            variation = "default"
            )
        var.save()
        img = m.Image(
            variation = var,
            image = i[5]
            )
        img.save()
        size = m.Size(
            variation = var
            )
        size.save()
        price = m.Price(
            variation = var,
            price = float(i[3])
            )
        price.save()
        stock = m.Stock(
            size = size,
            stock = Stock_CHOICES[i[9]] if i[9] in Stock_CHOICES else 4
            )
        stock.save()
        prod.category.add(cat)

Error: 错误:

Traceback (most recent call last):
  File "update_fromcsv.py", line 18, in <module>
    l = list(csv.reader(open('test_data.csv', encoding='utf-8', errors='ignore')))
TypeError: 'errors' is an invalid keyword argument for this function

You are using different versions of Python locally and on the server. 您正在本地和在服务器上使用不同版本的Python。

Locally, you are likely using Python 3, because Python 3.4 knows the errors argument for open() 在本地,您可能会使用Python 3,因为Python 3.4知道 open()errors参数。

open(file, mode='r', buffering=-1, encoding=None, errors=None, 
     newline=None, closefd=True, opener=None)

On the server, you probably run Python 2, because in in Python 2.7 the errors argument does not exist 在服务器上,您可能运行了Python 2,因为在Python 2.7中errors参数不存在

open(name[, mode[, buffering]])

That's why the error message is complaining about 'errors' being "invalid". 这就是错误消息抱怨“错误”为“无效”的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 代码在本地运行良好,但 Codeforces 中的运行时错误? - Code works fine locally, but runtime error in Codeforces? Django表单不在生产服务器上呈现 - 使用testserver在本地工作正常,并且单元测试在生产服务器上传递 - Django forms not rendering on production server - work fine locally with testserver, and unit tests pass on production server Django登录自定义身份验证在本地有效,但不能在生产服务器上使用 - Django Login Custom Auth works locally but not on production server 为什么Amazon S3签名的URL在本地运行但不能在生产服务器上运行? - Why Amazon S3 signed URL works locally but not on production server? 远程站点上的 Django 错误 NoReverseMatch 但在本地工作正常 - Django error NoReverseMatch on remote site but works fine locally 仅在VPS上执行TemplateDoesNotExist Django错误-在本地运行良好 - TemplateDoesNotExist Django Error only on VPS - works fine locally Django PasswordResetTokenGenerator, check_token(user, token) 在生产中返回 False,本地工作正常 - Django PasswordResetTokenGenerator, check_token(user, token) returns False on Production, Locally Works Fine 烧瓶重定向在生产服务器上附加get%20 /%20HTTP / 1.1)uri。 在当地工作良好 - Flask redirect appends get%20/%20HTTP/1.1)uri on production server. Working fine locally Flask 在本地工作,但不在服务器上? - Flask works locally, but not on a server? 在服务器上部署时找不到文件,但在本地测试应用程序时工作正常 - File not found when deployed on server, but works fine when app is tested locally
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM