Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSV import fails with error: '_csv.reader' object has no attribute 'next' #1268

Closed
candlerb opened this issue Jun 14, 2017 · 0 comments
Closed
Labels
type: bug A confirmed report of unexpected behavior in the application

Comments

@candlerb
Copy link
Contributor

Issue type: Bug

Python version: 3.5.2 (Ubuntu 16.04)
NetBox version: 2.0.6

To reproduce: go to Racks, Import Racks; paste the following and hit Submit

site,name,width,u_height
SomeSite,Foo,42,19

Result is a Server Error:

<class 'AttributeError'>

'_csv.reader' object has no attribute 'next'

Traceback received via E-mail:

    File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py" in inner
      41.             response = get_response(request)
    
    File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py" in _get_response
      187.                 response = self.process_exception_by_middleware(e, request)
    
    File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py" in _get_response
      185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)
    
    File "/usr/local/lib/python3.5/dist-packages/django/views/generic/base.py" in view
      68.             return self.dispatch(request, *args, **kwargs)
    
    File "/usr/local/lib/python3.5/dist-packages/django/contrib/auth/mixins.py" in dispatch
      92.         return super(PermissionRequiredMixin, self).dispatch(request, *args, **kwargs)
    
    File "/usr/local/lib/python3.5/dist-packages/django/views/generic/base.py" in dispatch
      88.         return handler(request, *args, **kwargs)
    
    File "/opt/netbox/netbox/utilities/views.py" in post
      418.         if form.is_valid():
    
    File "/usr/local/lib/python3.5/dist-packages/django/forms/forms.py" in is_valid
      183.         return self.is_bound and not self.errors
    
    File "/usr/local/lib/python3.5/dist-packages/django/forms/forms.py" in errors
      175.             self.full_clean()
    
    File "/usr/local/lib/python3.5/dist-packages/django/forms/forms.py" in full_clean
      384.         self._clean_fields()
    
    File "/usr/local/lib/python3.5/dist-packages/django/forms/forms.py" in _clean_fields
      402.                     value = field.clean(value)
    
    File "/usr/local/lib/python3.5/dist-packages/django/forms/fields.py" in clean
      160.         value = self.to_python(value)
    
    File "/opt/netbox/netbox/utilities/forms.py" in to_python
      252.         headers = reader.next()
    
    Exception Type: AttributeError at /dcim/racks/import/
    Exception Value: '_csv.reader' object has no attribute 'next'

Judging by this post it appears to be a python 2/3 difference.

Applied following patch by hand:

--- /opt/netbox/netbox/utilities/forms.py.orig	2017-06-13 11:32:37.171228169 +0000
+++ /opt/netbox/netbox/utilities/forms.py	2017-06-14 12:47:19.245315962 +0000
@@ -249,7 +249,7 @@
         reader = csv.reader(value.splitlines())

         # Consume and valdiate the first line of CSV data as column headers
-        headers = reader.next()
+        headers = next(reader)
         for f in self.required_fields:
             if f not in headers:
                 raise forms.ValidationError('Required column header "{}" not found.'.format(f))

That appears to fix the problem.

@jeremystretch jeremystretch added the type: bug A confirmed report of unexpected behavior in the application label Jun 14, 2017
lampwins pushed a commit to lampwins/netbox that referenced this issue Oct 13, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

2 participants