[英]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.