AttributeError: module 'tensorflow_estimator.python.estimator.api._v1.estimator' has no attribute 'layers' - tensorflow-estimator

attr = getattr(self._tfmw_wrapped_module, name)
AttributeError: module 'tensorflow_estimator.python.estimator.api._v1.estimator' has no attribute 'layers'

Related

psutil AttributeError: 'ModuleWrapper' object has no attribute 'NoSuchprocess'

for myprocess in psutil.process_iter():
try:
myexe = myprocess.cmdline()
except psutil.NoSuchprocess:
myexe = None
This show an error
AttributeError: 'ModuleWrapper' object has no attribute 'NoSuchprocess'

attribute error on value for field on serializer django rest framework

I am receving the following error:
AttributeError: Got AttributeError when attempting to get a value for field `city` on serializer `SearchCitySerializer`
my serializers are correct though unless I am clearly missing something.
Here is my model:
class SearchCity(models.Model):
city = models.CharField(max_length=200)
here is my serializer
class SearchCitySerializer(serializers.ModelSerializer):
class Meta:
model = SearchCity
fields = ('pk','city')
*** I tried the serializer without the pk in the field and it still failed
and here it is used in the view:
from serializers import SearchCitySerializer
def get(self, request, format=None):
searchcityqueryset = SearchCity.objects.all()
serializedsearchcity = SearchCitySerializer(searchcityqueryset)
return Response({
'searchcity': serializedsearchcity.data,
})
the full error I am getting:
File "/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/backend/virtualsuits/suitsandtables/suitsandtablessettingsapp/views.py", line 37, in get
'searchcity': serializedsearchcity.data,
File "/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/backend/virtualsuits/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 537, in data
ret = super(Serializer, self).data
File "/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/backend/virtualsuits/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 262, in data
self._data = self.to_representation(self.instance)
File "/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/backend/virtualsuits/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 491, in to_representation
attribute = field.get_attribute(instance)
File "/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/backend/virtualsuits/local/lib/python2.7/site-packages/rest_framework/fields.py", line 462, in get_attribute
raise type(exc)(msg)
AttributeError: Got AttributeError when attempting to get a value for field `city` on serializer `SearchCitySerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `QuerySet` instance.
Original exception text was: 'QuerySet' object has no attribute 'city'.
[28/Feb/2018 02:41:43] "GET /api/dependancy/suitsadmin/settings/ HTTP/1.1" 500 20823
THE DATABASE IS CURRENTLY EMPTY AS IN NO DATA IN THE DATABASE AT ALL
serializedsearchcity = SearchCitySerializer(searchcityqueryset)
change to
serializedsearchcity = SearchCitySerializer(searchcityqueryset, many=True)
To serialize a queryset or list of objects instead of a single object instance, you should pass the many=True flag when instantiating the serializer. You can then pass a queryset or list of objects to be serialized.
Dealing with multiple objects

Attribute Dict -- TypeError raised when getting documentation

I wrote an "AttributeDict"-like object from the Alchin 'pro python' book, (below is taken almost directly from the book. My goal is to create a config object where the config fields are accessible as class attributes).
class ADict(dict):
def __setattr__(self,key,value):
self[key] = value
def __getattr__(self,key):
return self[key]
When I try to access the documentation I get a TypeError, related to a missing __name__ attribute (example below).
>>> z = ADict()
>>> help(z)
line 1531, in doc
pager(render_doc(thing, title, forceload))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pydoc.py", line 1505, in render_doc
object, name = resolve(thing, forceload)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pydoc.py", line 1500, in resolve
name = getattr(thing, '__name__', None)
File "attributeConfig.py", line 26, in __getattr__
return self[key]
KeyError: '__name__'
What's going on here? It's not obvious to me where this __name__ is going to (and how it's being used in the pydoc code).
You need to make sure an AttributeError is raised when the attribute couldn't be found:
class ADict(dict):
def __setattr__(self,key,value):
self[key] = value
def __getattr__(self,key):
try:
return self[key]
except KeyError:
raise AttributeError
This will lookup the attribute in the dictionary first. If it's there, return it. Otherwise, use raise an AttributeError to indicate that the attribute isn't there.

Specify template name from field value

Im trying to write a DetailView to use a field in the model called template_name where I could specify the template name on each entry (like the flatpages model). Im trying to use DetailView, but maybe I should not use it?
Here is what I have tried to write, but I get a this error: 'NoneType' object has no attribute 'render'
class EntryDetailView(DetailView):
model = Entry
def get_template_names(Entry, **kwargs):
if Entry.template_name:
template_name = "entry/%s" % Entry.template_name
else:
template_name = "entry/entry_detail.html"
Any tips on how to get it right?
Edit:
Here is mye traceback:
Traceback:
File "/home/USER/.virtualenvs/PROJECT/src/Django-1.6b2/django/core/handlers/base.py" in get_response
139. response = response.render()
File "/home/USER/.virtualenvs/PROJECT/src/Django-1.6b2/django/template/response.py" in render
105. self.content = self.rendered_content
File "/home/USER/.virtualenvs/PROJECT/src/Django-1.6b2/django/template/response.py" in rendered_content
82. content = template.render(context)
Exception Type: AttributeError at /entries/test/
Exception Value: 'NoneType' object has no attribute 'render'
Try this (assuming Django 1.5):
class EntryDetailView(DetailView):
model = Entry
template_name_field = 'template_name'
Docs about template_name_field.

TypeError while rendering: 'long' object is not iterable

I have a few models with some ForeignKey relationship.
Through forms.py I added a ModelMultipleChoiceField widget
class VariableFieldForm(ModelForm):
custom_field = forms.ModelMultipleChoiceField(queryset=VariableField.objects.all(), widget=FilteredSelectMultiple("Custom Fields", is_stacked=False))
class Meta:
model = VariableField
and when trying to access a saved record localhost:8000/admin/product/subcategory/3/ or saving a new record I get the following traceback
File "/opt/python2.6/lib/python2.6/site-packages/django/utils/encoding.py" in force_unicode
71. s = unicode(s)
File "/opt/python2.6/lib/python2.6/site-packages/django/forms/forms.py" in __unicode__
408. return self.as_widget()
File "/opt/python2.6/lib/python2.6/site-packages/django/forms/forms.py" in as_widget
439. return widget.render(name, self.value(), attrs=attrs)
File "/opt/python2.6/lib/python2.6/site-packages/django/contrib/admin/widgets.py" in render
39. output = [super(FilteredSelectMultiple, self).render(name, value, attrs, choices)]
File "/opt/python2.6/lib/python2.6/site-packages/django/forms/widgets.py" in render
581. options = self.render_options(choices, value)
File "/opt/python2.6/lib/python2.6/site-packages/django/forms/widgets.py" in render_options
531. selected_choices = set([force_unicode(v) for v in selected_choices])
Exception Type: TemplateSyntaxError at /admin/product/subcategory/3/
Exception Value: Caught TypeError while rendering: 'long' object is not iterable
I am using Django 1.3 and MySQL
Ideas on how to solve it?
Ended up being that I used a ForeignKey, instead of a ManyToManyField relation.
Hope this helps any future questions