Reputation: 199
I'm trying to import this CSV file. It works perfectly on my local setup on django. However- it won't import on my actual server/production version.
I am using SQLite (locally), and Postgres on the server. 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
Upvotes: 0
Views: 82
Reputation: 12558
You are using different versions of Python locally and on the server.
Locally, you are likely using Python 3, because Python 3.4 knows the errors
argument for open()
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
open(name[, mode[, buffering]])
That's why the error message is complaining about 'errors' being "invalid".
Upvotes: 1