Something in your program is trying to call the startswith method of an object, probably because it expects it to be a string. You'll have to pay attention to the traceback to see what it is being called on, and why that is an integer instead of a string. Did you pass along an integer where a string was expected?
Something in your program is trying to call the startswith method of an object, probably because it expects it to be a string. You'll have to pay attention to the traceback to see what it is being called on, and why that is an integer instead of a string. Did you pass along an integer where a string was expected?
startswith only works with strings.
If you need to check if an int starts with a set of numbers, you can convert it to a string, i.e.:
someint = 1234
if str(someint).startswith("123"):
# do somenting
classification report throws 'int' object has no attribute 'startswith'
python - Trying to get rid of "AttributeError: 'int' object has no attribute 'startswith' " when using while loop - Stack Overflow
'int' object has no attribute 'startswith' when using an int as key
Command raised an exception: AttributeError: 'int' object has no attribute 'startswith'
So ive googled and tried to change my code based on the other answers ive found, but i keep getting that error code.
Here is my code:
def genre_find(user_id):
global response_user_id
global response
global genreif
if response_user_id != user_id:
response = requests.get('https://www.fanfiction.net/u/{}'.format(user_id))
response_user_id = user_id
sleep(randint(3, 4))
if response.status_code == requests.codes.ok:
soup = bs(response.text, 'html.parser')
user_info = soup.select("#content_wrapper_inner table table tr td")
my_stories = soup.select("div.mystories")
genre = None
for story in my_stories:
genre = story.find_all("div")[-1].text.split(" - ")[3]
return genre
genreif = genre.startswith('Chap')
return genreifError: (line 17 here)
File "test_two.py", line 74, in <module>
user_write_story_data = get_user_information(user_id)
File "test_two.py", line 42, in get_user_information
genre_find(user_id)
File "test_two.py", line 34, in genre_find
genreif = genre.startswith('Chap')
AttributeError: 'NoneType' object has no attribute 'startswith'Solved by upgrading celery to It's latest version from 4.4.2 to 5.1.2.
Seems like version 4.4.2 (which is a one of airflow deps) had a bug with arguments.
If there are any other suggestions how to solve this issue, feel free to mention them here.
For airflow 2.1.0+, you need celery 5.1.2+
Documentation is here: https://airflow.apache.org/docs/apache-airflow-providers-celery/stable/index.html#pip-requirements which explains the need for celery 5.1.2+
I've been working on setting up a "simple" Flask app with a cloud-hosted postgres database.
My app's config.py file includes the following code:
SQLALCHEMY_DATABASE_URI = os.environ.get('dbs_url')
if os.environ.get('dbs_url').startswith('postgres') :
SQLALCHEMY_DATABASE_URI = os.environ.get('dbs_url').replace('postgres', 'postgresql')Long story short, this is included because ElephantSQL starts their database URLs with "postgres" while SQLAlchemy expects them to begin with "postgresql".
Generally speaking this has worked just fine.
Now, though, I'm in a situation where I need to edit a local database entry directly (I added a new column to an existing table). As far as I know I need to enter Python's shell and import the database model that represents the offending table, like >>> from [app] import [Class]. Apparently doing that involves pulling from the config.py file somehow, because when I try importing a model I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\colby\coding_temple\assignments\week_5\01\homework\app\
from config import Conf
File "C:\Users\colby\coding_temple\assignments\week_5\01\homework\conf
class Conf:
File "C:\Users\colby\coding_temple\assignments\week_5\01\homework\conf
if os.environ.get('dbs_url').startswith('postgres'):
AttributeError: 'NoneType' object has no attribute 'startswith'Regardless of whether what I'm doing makes any sense (I'm sure it doesn't), I'd like to re-write this in a way that doesn't cause this error.
Edit: I was indeed doing something that didn't make any sense. I didn't need to try this at all, just delete a row from my ElephantSQL database. Not sure why I thought there was something locally