ImportError: Cannot import name 'DurationField' - python

I am trying to run an application that uses django (version 1.6.5) rest framework ( python version 3.4.5 ) .However I am getting the Import error "cannot import name DurationField".How do I resolve this error ?
File "/usr/src/app/Lab/models.py", line 8, in <module>
from Lab import logic, common <br>
File "/usr/src/app/Lab/logic.py", line 16, in <module>
from Rest import viewsAppComm <br>
File "/usr/src/app/Rest/viewsAppComm.py", line 7, in <module>
from rest_framework.response import Response <br>
File "/usr/local/lib/python3.4/site-packages/rest_framework/response.py", line 13, in <module>
from rest_framework.serializers import Serializer
File "/usr/local/lib/python3.4/site-packages/rest_framework/serializers.py", line 19, in <module>
from django.db.models import DurationField as ModelDurationField <br>
ImportError: cannot import name 'DurationField'

DurationField was added in Django 1.8. You are using Django 1.6, hence the error.
Your options are to upgrade (which is a good idea if you can, because Django 1.6 has reached end of life quite a while ago) or to downgrade to an older version of Django Rest Framework (the version you currently have is not compatible with Django 1.6).
You may also be able to install the third-party django-duration-field app and then import it with:
from durationfield.db.models.fields.duration import DurationField
... but from the stack trace you posted it looks like it is DRF that is trying to import the model.

Related

ImportError: cannot import name types

I'm trying the app I cloned from following Github.
https://github.com/sfujiwara/qa-system-sample.git
(This app uses python flask, Google Natural Language API and so on.)
But, I cannot run this on Google App Engine.Following Error occurs.
Error:
ImportError: cannot import name types
at <module> (/base/data/home/apps/b~qa-system-sample2/20171223t122211.406411375873194303/lib/google/cloud/language_v1/__init__.py:17)
at <module> (/base/data/home/apps/b~qa-system-sample2/20171223t122211.406411375873194303/lib/google/cloud/language.py:17)
at <module> (/base/data/home/apps/b~qa-system-sample2/20171223t122211.406411375873194303/factoid.py:5)
at <module> (/base/data/home/apps/b~qa-system-sample2/20171223t122211.406411375873194303/main.py:9)
at LoadObject (/base/alloc/tmpfs/dynamic_runtimes/python27/54c5883f70296ec8_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py:85)
at _LoadHandler (/base/alloc/tmpfs/dynamic_runtimes/python27/54c5883f70296ec8_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py:299)
at Handle (/base/alloc/tmpfs/dynamic_runtimes/python27/54c5883f70296ec8_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py:240)
This occurs at from google.cloud.language_v1 import typesin lib/google/cloud/language_v1/_ _init__.py.
Although, There is types.py in /lib/google/cloud/language_v1.
I'm a beginner of python, so I couldn't find out a reason of this error.Please tell me the way to resolve this error.Thanks in advance.
I added enum into the library. It fixes this issue (although another import issue occurred)
libraries:
- name: enum
version: latest

Error connecting to SF object to get the ForecastingItem object description using beatbox - python

from a ubuntu machine I use beatbox python package to connect to SF and get the objects descriptions
but can't manage to get access to the ForecastingItems object.
I checked my privileges to access the object and I have full access as admin
the script I'm using is bellow, when I changed the object ForecastingItem with Account it does pull all the object fields.
#!/usr/bin/python
# coding=utf8
import beatbox
import pprint
import sys
import os
import datetime
sf_service = beatbox.PythonClient()
sf_service.login('email#hotmail.com', 'password$numbersletter')
desc_obj = sf_service.describeSObjects('ForecastingItem')
forcat_item = desc_obj[0]
forItem_fields = forcat_item.fields
for sf_field_key, sf_field_value in forItem_fields.items():
print sf_field_key
I heard that I should upgrade beatbox to something more than the version 21 to be able to access the ForecastingItem object so I tried apt-get update upgrade beatbox, but I still get the error :
Traceback (most recent call last):
File "./fields_associated_with_an_object.py", line 14, in <module>
desc_obj = sf_service.describeSObjects('ForecastingItem')
File "/usr/local/lib/python2.7/dist-packages/beatbox-20.0-py2.7.egg/beatbox/python_client.py", line 131, in describeSObjects
res = BaseClient.describeSObjects(self, sObjectTypes)
File "/usr/local/lib/python2.7/dist-packages/beatbox-20.0-py2.7.egg/beatbox/_beatbox.py", line 108, in describeSObjects
return DescribeSObjectsRequest(self.__serverUrl, self.sessionId, sObjectTypes).post(self.__conn)
File "/usr/local/lib/python2.7/dist-packages/beatbox-20.0-py2.7.egg/beatbox/_beatbox.py", line 332, in post
raise SoapFaultError(faultCode, faultString)
beatbox._beatbox.SoapFaultError: 'INVALID_TYPE' "INVALID_TYPE: sObject type 'ForecastingItem' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names."
Thanks in advance!

Python import error. Circular imports

I'm creating a simple flask app. I'm using blueprints to provide views and OpenID for login. I have faced the problem when I try to import created OpenID object to the file with the views interpreter throws an Import Error.
Traceback (most recent call last):
File "/.../ProgList/ProgList.py", line 11, in <module>
from views_admin import views as views_a
File "/.../ProgList/views_admin.py", line 4, in <module>
from ProgList import open_id
File "/.../ProgList/ProgList.py", line 11, in <module>
from views_admin import views as views_a
ImportError: cannot import name 'views'
ProgList.py
# importing VIEWS
from views import views
from views_admin import views as views_a
...
open_id = OpenID(app, 'temp_dir_path')
views_admin.py
from ProgList import open_id
...
#views.route("/login", methods=["GET", "POST"])
#open_id.loginhandler
def login():
I have been struggling this problem for hours and couldn't find an answer.
Thank you very much for help.
In ProgList, you import views_admin, in views_admin, you import ProgList. This cannot be resolved. The typical approach here is to outsource something to a third file which both can safely access without interfering with each other. From the looks of it, you might want to move open_id into a different file.

Django views ImportError

I don't know if this logic is correct,
I'm trying to import a Django view in 2 different views.
I have an import chain like this:
the
a.views import b.views
b.views import c.views
c.views import d.views
and
d.views import b.views
but when I reach the last step I get an ImportError.
If I put a comment in d.views avoiding the import of b.views, it works.
I'm new with Django, can somebody help me?
If I use in a.views and in d.views the syntax
from b.views import *
it works, but.. the code is not so readable.
If I use
from b.views import my_func
it doesn't work!
This is the error from django shell:
>>> import maps.views
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/save/sites/myblog/maps/views.py", line 19, in <module>
from places.views import *
File "/Users/save/sites/myblog/places/views.py", line 22, in <module>
from posts.views import *
File "/Users/save/sites/myblog/posts/views.py", line 31, in <module>
from maps.views import render_map_geoloc
ImportError: cannot import name render_map_geoloc
Its because of cyclic dependency or circular reference.
b depends on c
c depends on d
d depends on b #which depends on c
Not sure for what purpose you are using. But you do explicit import to that function, and right above where its been used.
Looking at the error you are getting, it might be because of some dependency expected for d is coming from b so if you from b.views import *, it gets you that dependency. But if you import specific view (my_func), its missing that dependency.
Some more details you can find on SO answer thread - Django App Dependency Cycle

AttributeError for SUDS in GAE

I am trying to include the SUDS library in a Python project through Google App Engine.
My code tries the following:
from suds.client import Client
from suds.wsse import *
And, once I've deployed on GAE, I encounter the following error:
File ".../myfile.py", line 13, in <module>
from suds.client import Client
File ".../suds/__init__.py", line 154, in <module>
import client
File ".../suds/client.py", line 25, in <module>
import suds.metrics as metrics
AttributeError: 'module' object has no attribute 'suds'
I've been looking around for a little while, and it seems like SUDS is workable with GAE. I added the fixes outlined here, but that doesn't seem to be the problem. It seems like App Engine doesn't even get to that point.
Any info or suggestions?
I'm using Python 2.7 and SUDS 0.4.
Have you tried doing a simple import suds.client? Also make sure you include the suds folder in your application as App Engine doesn't include it by default. I hope that helps.

Categories