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?

Answer from Thomas Wouters on Stack Overflow
🌐
Bobby Hadz
bobbyhadz.com › blog › python-attributeerror-int-object-has-no-attribute
AttributeError: 'int' object has no attribute 'X' (Python) | bobbyhadz
The Python "AttributeError: 'int' object has no attribute" occurs when we try to access an attribute that doesn't exist on an integer. To solve the error, make sure the value is of the expected type before accessing the attribute.
Discussions

python - Trying to get rid of "AttributeError: 'int' object has no attribute 'startswith' " when using while loop - Stack Overflow
Okay, thanks Engr1hmh, i've changed the assignment from line =0 to count= 0 instead. Now in addition to "count" variable I have modified the while block to below. while count< line_count: if line.startswith("From"): print(line) count= count+ 1 Now i don't get any output whatsoever. More on stackoverflow.com
🌐 stackoverflow.com
'int' object has no attribute 'startswith' when using an int as key
I get: 'int' object has no attribute 'startswith' when trying to give an int as a key. ... File "/usr/local/lib/python3.4/dist-packages/pickleshare.py", line 90, in __setitem__ fil = self.root / key File "/usr/local/lib/python3.4/dist-packages/path.py", line 255, in __div__ return ... More on github.com
🌐 github.com
1
March 30, 2016
Getting a 'NoneType' object has no attribute 'startswith' AttributeError, and i cant figure it out.
If my_stories is empty the for loop doesn't iterate and genre is still None. Use some string instead of none as default for genre. More on reddit.com
🌐 r/learnpython
3
2
July 22, 2018
classification report throws 'int' object has no attribute 'startswith'
I am trying to print a Classification report and I get the below error: I did check if any int values are passed in the list and there were none, infact I also made sure to convert them to string b... More on github.com
🌐 github.com
1
February 22, 2022
🌐
GitHub
github.com › martinblech › xmltodict › issues › 249
AttributeError: 'int' object has no attribute 'startswith' · Issue #249 · martinblech/xmltodict
June 5, 2020 - Traceback (most recent call last): File "bug.py", line 3, in <module> print(xd.unparse({ File "C:\Users\andreasxp\Miniconda3\envs\nfb_studio\lib\site-packages\xmltodict.py", line 450, in unparse _emit(key, value, content_handler, full_document=full_document, File "C:\Users\andreasxp\Miniconda3\envs\nfb_studio\lib\site-packages\xmltodict.py", line 388, in _emit if ik.startswith(attr_prefix): AttributeError: 'int' object has no attribute 'startswith'
Author   martinblech
🌐
Stack Overflow
stackoverflow.com › questions › 66929877 › trying-to-get-rid-of-attributeerror-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
line_count =0 line =0 for i in fhand: line_count = line_count +1 print("Total lines:", line_count) while line < line_count: if line.startswith("From:"): print(line) line = line +1 · RESULT: AttributeError: 'int' object has no attribute 'startswith'
🌐
Python
bugs.python.org › issue8570
Issue 8570: 2to3 crashes with "AttributeError: 'int' object has no attribute 'startswith'" - Python tracker
This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/52816
🌐
GitHub
github.com › pickleshare › pickleshare › issues › 20
'int' object has no attribute 'startswith' when using an int as key · Issue #20 · ipython/pickleshare
March 30, 2016 - I get: 'int' object has no attribute 'startswith' when trying to give an int as a key. ... File "/usr/local/lib/python3.4/dist-packages/pickleshare.py", line 90, in __setitem__ fil = self.root / key File "/usr/local/lib/python3.4/dist-packages/path.py", line 255, in __div__ return self._next_class(self.module.join(self, rel)) File "/usr/lib/python3.4/posixpath.py", line 79, in join if b.startswith(sep): AttributeError: 'int' object has no attribute 'startswith'
Author   ipython
🌐
Reddit
reddit.com › r/learnpython › getting a 'nonetype' object has no attribute 'startswith' attributeerror, and i cant figure it out.
r/learnpython on Reddit: Getting a 'NoneType' object has no attribute 'startswith' AttributeError, and i cant figure it out.
July 22, 2018 -

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 genreif

Error: (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'
🌐
Delft Stack
delftstack.com › home › howto › python › int object has no attribute
How to Fix AttributeError: Int Object Has No Attribute | Delft Stack
March 11, 2025 - When working with Python, encountering errors is part of the learning process. One common issue developers face is the “AttributeError: ‘int’ object has no attribute” error. This error usually occurs when you’re trying to access an attribute or method that doesn’t exist for an integer object.
Find elsewhere
🌐
Brainly
brainly.com › computers and technology › high school › what does "int object has no attribute" mean in python?
[FREE] What does "int object has no attribute" mean in Python? - brainly.com
November 19, 2023 - When Python raises the error 'int object has no attribute', it indicates that you are attempting to access an attribute or method on an integer (an int object) that does not exist for the int type.
🌐
GitHub
github.com › chakki-works › seqeval › issues › 87
classification report throws 'int' object has no attribute 'startswith' · Issue #87 · chakki-works/seqeval
February 22, 2022 - --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-160-2ad87943346a> in <module> ----> 1 print(classification_report(correctLabels, predLabels)) ~\Anaconda3\lib\site-packages\seqeval\metrics\sequence_labeling.py in classification_report(y_true, y_pred, digits, suffix, output_dict, mode, sample_weight, zero_division, scheme) 677 ) 678 --> 679 target_names_true = {type_name for type_name, _, _ in get_entities(y_true, suffix)} 680 target_names_pred = {type_name for type_name, _, _ in get_entities(y_pred, suff
Author   chakki-works
🌐
Reddit
reddit.com › r/learnpython › attributeerror: 'nonetype' object has no attribute 'startswith'
r/learnpython on Reddit: AttributeError: 'NoneType' object has no attribute 'startswith'
September 22, 2021 -

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

🌐
Tutorial Reference
tutorialreference.com › python › examples › faq › python-error-attributeerror-int-object-has-no-attribute-x
How to Resolve Python "AttributeError: 'int' object has no attribute '...'" | Tutorial Reference
... Solution: Convert to str before calling the method, or ensure the variable holds a str in the first place. ... While fixing the root cause is best, you can sometimes use the built-in hasattr() function to check if an object has a specific attribute/method before attempting to access it.
🌐
M5Stack Community
community.m5stack.com › topic › 5805 › int-object-has-no-attribute-startwith-error-when-trying-to-use-an-image
'int' object has no attribute 'startwith' ERROR when trying to use an image | M5Stack Community
November 14, 2023 - Details of the error say the following: File "<string>", line 39 in <module> // I think it refers to this line: image0 = M5Img(135, 82, "res/error.png", True) File "m5stack_ui.py", line 513, in _ init _ AttributeError: 'int' object has no attribute 'startswith'
🌐
Team Treehouse
teamtreehouse.com › community › int-object-has-no-attribute-numdie
int object has no attribute 'num_die' (Example) | Treehouse Community
August 17, 2021 - I set this up a bit differently from the video, but it seems like it should work. PyCharm tells me the num_die attribute is an integer, but when the code runs, it says int object has no attribute 'num_die' The die class and the die roller class work just fine, but then it stops in the for-loop of the dice_hand method.
🌐
SABnzbd Forums
forums.sabnzbd.org › home › board index › other languages › nederlands
AttributeError: 'int' object has no attribute 'startswith' - SABnzbd Forums
March 14, 2010 - Ik heb een upgrade gedaan naar ... cherryport, https_port) File "/opt/SABnzbd/SABnzbd.py", line 445, in get_webhost if ip.startswith('169.254.'): AttributeError: 'int' object has no attribute 'startswith' Op de verschillende formus gezocht maar geen oplossing gevonden, ...
🌐
Google Groups
groups.google.com › g › sima-users › c › WLVCz5sdpjo
AttributeError: 'list' object has no attribute 'startswith'
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 61, in isabs · return s.startswith('/') AttributeError: 'list' object has no attribute 'startswith'" The example dataset works fine with the provided example script (workflow.py), so I'm sure this is a rather trivial error/conflict regarding working directories or filename formats or something like this.
🌐
Reddit
reddit.com › r/learnpython › attributeerror: 'int' object has no attribute 'get', on dictionary
r/learnpython on Reddit: AttributeError: 'int' object has no attribute 'get', on dictionary
December 6, 2022 -

I'm creating frequency dicts of lemmas and words, but have encountered this error and have no clue on what's going on, can anyone help me make sense of this?

If there's a better way of doing this please do tell!

https://imgur.com/a/sUR7DEJ

freq = defaultdict(dict) 
def spcy(content, dir): 
code = str(dir.lower())
model = code + "_core_news_sm"
models = spacy.util.get_installed_models()

if model in models:
    #try:
        nlp = spacy.load(model)
        #print(model)
        spcy = nlp(content)

        for word in spcy:
            if word.text.isalpha():
                print(word)
                print(type(freq.get(word.lemma_,{})))
                freq[word.lemma_][word.text] = freq.get(word.lemma_,{}).get(word.text, 0) + 1

    #except:
        #print("exception")

    #print(freq)

elif not model in models:
    nlp = spacy.blank(code)
    spcy = nlp(content)

    for word in spcy:
        if word.text.isalpha():
            #does work...
            freq[word.text] = freq.get(word.text, 0) + 1  # type: ignore

    print(freq)
🌐
Ansible
forum.ansible.com › archives › ansible project
dig lookup exception: 'list' object has no attribute 'startswith' - Ansible Project - Ansible
December 10, 2018 - Hey all- I’m having more problems w/ the dig lookup. If I statically define a list of hosts to lookup as a variable, it works. But if I return the list of hosts from another script, it fails. Here’s a simple example: ` $ cat test.py #!/usr/bin/env python import json hostList = hostList.append((‘www.google.com’)) j = {} j[‘hosts’] = hostList print json.dumps(j) $ cat test.yml
🌐
Codecademy
codecademy.com › forum_questions › 504a103b1c9a5e000206c040
[solved] AttributeError: 'int' object has no attribute 'insert' | Codecademy
The data type of the value associated to key ‘gold’ is an integer. What you want to do is change the value by adding 50 to it.