• Register
0 votes
238 views

Problem :

When I try to run following command: python manage.py updatestats I get the error as below:

“TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'”

I am unable to figure out what is causing this. I have already tried to convert it to the string, but still I get the same error. Any ideas?

Error traceback:

Traceback (most recent call last):
File "manage.py", line 31, in <module>
execute_from_command_line(sys.argv)
File "/Users/alecxe/project/Dev/lib/python3.4/site-packages/django/core/management/__init__.py", line 450, in execute_from_command_line
utility.execute()
File "/Users/alecxe/project/Dev/lib/python3.4/site-packages/django/core/management/__init__.py", line 444, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/alecxe/project/Dev/lib/python3.4/site-packages/django/core/management/base.py", line 448, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/alecxe/project/Dev/lib/python3.4/site-packages/django/core/management/base.py", line 400, in execute
output = self.handle(*args, **options)
File "/Users/alecxe/project/Dev/project_files/project/main/management/commands/updatestats.py", line 34, in handle
unique_visits=display_unique_visits(hostname),)

 

6 5 3
7,540 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

What this error is telling you is that you should not convert the entire list into the integer. You should get the index from a list and then simply convert that into an integer:

a= ["0", "1", "2"] 
b = int(a[0]) #accessing a zeroth element

If the list elements are not the strings then you will need to convert them to the strings before using the str.join as shown below:

a = [0, 1, 2]
b = ''.join(map(str, a))
c = int(b)

Also, as shown above please make sure that you are not returning the nested list.

9 7 4
38,600 points

Related questions

0 votes
1 answer 1.9K views
1.9K views
Problem : I am facing the issue in passing a function as a parameter to another function as follows typeerror: int() argument must be a string, a bytes-like object or a number, not 'nonetype'
asked Nov 18, 2019 peterlaw 6.9k points
0 votes
1 answer 5 views
5 views
Program: I having trouble passing a function as a parameter to another function. This is my code: ga.py: def display_pageviews(hostname): pageviews_results = get_pageviews_query(service, hostname).execute() if pageviews_results.get('rows', []): pv = pageviews_results.get('rows') ... ='7daysAgo', end_date='today', metrics='ga:pageviews', sort='-ga:pageviews', filters='ga:hostname==%s' % hostname,)
asked 4 days ago Mashhoodch 5.6k points
0 votes
1 answer 16 views
0 votes
1 answer 83 views
83 views
Problem: I have freshly migrated my project from the old python2 to the new python3 and it has hundreds of the ForeignKey relations. I have very basic knowledge related to python. Using a solution to go line by line and add on_delete argument is not the possible. What ... it does not look like catching it somehow. Looking for a Python expert who can try to fix my above Python error very quickly.
asked Jul 15, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 1.3K views
1.3K views
Problem : I am trying to convert my working Python 2.7 code into Python 3 code but I am facing following error post data should be bytes, an iterable of bytes, or a file object. it cannot be of type str.
asked Nov 16, 2019 peterlaw 6.9k points
0 votes
1 answer 2K views
2K views
Problem : I am at my minds end. After a lot of hours of troubleshooting, probably more than 20, I thought I was finally in business, but then I got following error : Model class django.contrib.contenttypes.models.ContentType doesn't ... class MyDeletenoteConfig(AppConfig): name = 'MyDeleteNote' and from django.apps import AppConfig class MyLibrarysyncConfig(AppConfig): name = 'MyLibrarySync'
asked Dec 16, 2019 alecxe 7.5k points
0 votes
2 answers 1.1K views
1.1K views
Problem : I am new to Py 3.5. This code was working properly in Python 2.7: with open(fname, 'rb') as f: lines = [x.strip() for x in f.readlines()] for line in lines: tmp = line.strip().lower() if 'some-pattern' in tmp: continue # ... code After upgrading to 3.5, I'm getting the: TypeError: a bytes-like object is required, not 'str'
asked Oct 22, 2019 peterlaw 6.9k points
0 votes
1 answer 2K views
2K views
Problem : MySample.csv contains the below details : NAME Id No Dept Tommy 1 12 CS Jimmy 2 35 EC Bonny 3 21 IT Franky 4 61 EE And my Python file contains the below code : import csv myifile = open('mysample.csv', "rb") read = csv.reader(myifile) for row in read : ... in for row in read : _csv.Error: iterator should return strings, not bytes (did you open the file in text mode?) How should I fix it?
asked Jan 2, 2020 alecxe 7.5k points
1 vote
1 answer 56 views
56 views
Problem : I want to learn the python programming and also want to work on projects. One of my projects is to code the voting system so that it can select the best player among 23 players of a match by using the lists. I am currently using the Python3. Please ... any of the strings in my above code all my variables are of the type integers. Please guide me in fixing above python related error.
asked May 14, 2020 Martin K 6.6k points
1 vote
2 answers 99 views
99 views
Problem : The program supposed to take in two names, and if they are the same length it should check if they are the same word. But i am getting below error in python python typeerror: not all arguments converted during string formatting
asked Oct 21, 2019 peterlaw 6.9k points