attributeerror

TypeError: 'NoneType' object is not subscriptable followed by AttributeError: 'NoneType' object has no attribute 'split'

戏子无情 提交于 2019-12-06 02:06:14
问题 Using django. I have the following model: class Postagem(models.Model): id = models.AutoField(primary_key=True, editable=False) descricao = models.CharField(max_length=50) area = models.ForeignKey('core.Area', null=True) user = models.ForeignKey('User') categoria = models.CharField(max_length=50, null=True) post = models.FileField(upload_to='posts/', null=True) thumbnail = models.FileField(upload_to='posts/', null=True) def __str__(self): return self.descricao The Following form: class

Getting an AttributeError: <class> has no attribute <method>

浪子不回头ぞ 提交于 2019-12-05 18:04:05
问题 I am creating a method in a class in a module mod1 and calling it as follows: class blahblah: def foobar(self, bvar, **dvar) //// return dvar And calling it as: obj1 = mod1.blahblah() dvar1 = obj1.foobar(True, **somedictionary) It throws a Attribute error: blahblah has no attribute named foobar Could you please help me with it? Thanks in advance 回答1: The type of error you describe can be caused simply by mismatched indentation. If the method is at the very bottom of your class, move it up in

Python AttributeError: NoneType object has no attribute 'close'

一世执手 提交于 2019-12-05 12:19:09
I am learning python and I wrote a script that copies the content of one text file to another. Here is my code. from sys import argv out_file = open(argv[2], 'w').write(open(argv[1]).read()) out_file.close() I get the AttributeError listed on the title. Why is it that wen I call the write method on open(argv[2], 'w') the out_file is not assigned a File type? Thank you in advance out_file is being assigned to the return value of the write method, which is None . Break the statement into two: out_file = open(argv[2], 'w') out_file.write(open(argv[1]).read()) out_file.close() And really, it'd be

AttributeError: 'list' object has no attribute 'split'

心不动则不痛 提交于 2019-12-05 08:45:55
Using Python 2.7.3.1 I don't understand what the problem is with my coding! I get this error: AttributeError: 'list' object has no attribute 'split This is my code: myList = ['hello'] myList.split() You can simply do list(myList[0]) as below: >>> myList = ['hello'] >>> myList=list(myList[0]) >>> myList ['h', 'e', 'l', 'l', 'o'] See documentation here To achieve what you are looking for: myList = ['hello'] result = [c for c in myList[0]] # a list comprehension >>> print result ['h', 'e', 'l', 'l', 'o'] More info on list comprehensions: http://www.secnetix.de/olli/Python/list_comprehensions.hawk

AttributeError: 'module' object has no attribute 'SignedJwtAssertionCredentials'

删除回忆录丶 提交于 2019-12-04 19:59:40
问题 Problem : I've been using Python Script Samples by Google to upload the apk to Play Store and to get list of apps published via my account (list_apks.py and upload_apk.py ). However recently it started breaking. I've tried to update the packages like google-api-python-client , oath2client etc by doing pip install --update packagename but it didn't help. Logs : This if while listing apk's: Determining latest version for my.package.name... error 25-Feb-2016 06:30:52 Traceback (most recent call

Python attribute error: type object '_socketobject' has no attribute 'gethostbyname'

那年仲夏 提交于 2019-12-04 11:05:38
问题 I am trying to do this in my program: dest = socket.gethostbyname(host) I have included the line: from socket import * in the beginning of the file. I am getting this error: AttributeError: type object '_socketobject' has no attribute 'gethostbyname' I am running Vista 64bit. Could there be a problem with my OS? I have turned down my firewall and everything. 回答1: You shoulod either use import socket dest = socket.gethostbyname(host) or use from socket import * dest = gethostbyname(host) Note:

TypeError: 'NoneType' object is not subscriptable followed by AttributeError: 'NoneType' object has no attribute 'split'

≡放荡痞女 提交于 2019-12-04 06:04:37
Using django. I have the following model: class Postagem(models.Model): id = models.AutoField(primary_key=True, editable=False) descricao = models.CharField(max_length=50) area = models.ForeignKey('core.Area', null=True) user = models.ForeignKey('User') categoria = models.CharField(max_length=50, null=True) post = models.FileField(upload_to='posts/', null=True) thumbnail = models.FileField(upload_to='posts/', null=True) def __str__(self): return self.descricao The Following form: class PostForm(forms.ModelForm): categoria = forms.ChoiceField(choices=[("Video","Vídeo"),("Audio","Aúdio"),(

How to use gTTS in python?

本秂侑毒 提交于 2019-12-04 06:02:14
问题 When executing the below code from gtts import gTTS tts = gTTS('hello') tts.save('hello.mp3') I am getting "AttributeError: 'NoneType' object has no attribute 'group'". Traceback (most recent call last): File "C:\Users\HP\Desktop\Desktop\programming\Python_code\New Text Document - Copy (8) - Copy.py", line 3, in <module> tts.save('hello.mp3') File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\gtts\tts.py", line 247, in save self.write_to_fp(f) File "C:\Users\HP\AppData

Getting an AttributeError: <class> has no attribute <method>

社会主义新天地 提交于 2019-12-04 02:47:10
I am creating a method in a class in a module mod1 and calling it as follows: class blahblah: def foobar(self, bvar, **dvar) //// return dvar And calling it as: obj1 = mod1.blahblah() dvar1 = obj1.foobar(True, **somedictionary) It throws a Attribute error: blahblah has no attribute named foobar Could you please help me with it? Thanks in advance The type of error you describe can be caused simply by mismatched indentation. If the method is at the very bottom of your class, move it up in the class a bit and the problem will become apparent. When python interpreters run into mismatched indents

Python Selenium 'WebDriver' object has no attribute error

你。 提交于 2019-12-03 14:22:07
I'm trying to scrape some javascript-generated content from a Chinese-language website. I'm using Selenium (and Python) since I can't scrape the javascript content directly. # -*- coding: utf-8 -*- from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.selenium import selenium import time import urllib2 import httplib import urllib import re import base64 browser = webdriver.Firefox() # Get local session of firefox browser.get("http://www...") # Load page (redacted here, but any works) browser.get_body_text() #Attempt to scrape body text And I get the