dibgerge / ml-coursera-python-assignments

Python assignments for the machine learning class by andrew ng on coursera with complete submission for grading capability and re-written instructions.
5.45k stars 2.16k forks source link

TypeError #5

Closed datainvestor closed 5 years ago

datainvestor commented 6 years ago

When I try to submit first excercise to the grader Im getting following error:

TypeError                                 Traceback (most recent call last)
<ipython-input-5-a776c0c55379> in <module>()
      3 
      4 # send the added functions to coursera grader for getting a grade on this part
----> 5 grader.grade()

~\PythonProjects\ml-coursera-python-assignments\submission.py in grade(self)
     31             parts[str(part_id)] = {'output': sprintf('%0.5f ', result)}
     32         result, response = self.request(parts)
---> 33         response = json.loads(response)
     34 
     35         # if an error was returned, print it and stop

~\Anaconda3\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    310     if not isinstance(s, str):
    311         raise TypeError('the JSON object must be str, not {!r}'.format(
--> 312                             s.__class__.__name__))
    313     if s.startswith(u'\ufeff'):
    314         raise JSONDecodeError("Unexpected UTF-8 BOM (decode using utf-8-sig)",

TypeError: the JSON object must be str, not 'bytes'

What should I do ?

crudalex commented 6 years ago

Can you convert the data type of response to string

On Thu, Aug 23, 2018, 16:20 datainvestor notifications@github.com wrote:

When I try to submit first excercise to the grader Im getting following error:

TypeError Traceback (most recent call last)

in () 3 4 # send the added functions to coursera grader for getting a grade on this part ----> 5 grader.grade() ~\PythonProjects\ml-coursera-python-assignments\submission.py in grade(self) 31 parts[str(part_id)] = {'output': sprintf('%0.5f ', result)} 32 result, response = self.request(parts) ---> 33 response = json.loads(response) 34 35 # if an error was returned, print it and stop ~\Anaconda3\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 310 if not isinstance(s, str): 311 raise TypeError('the JSON object must be str, not {!r}'.format( --> 312 s.__class__.__name__)) 313 if s.startswith(u'\ufeff'): 314 raise JSONDecodeError("Unexpected UTF-8 BOM (decode using utf-8-sig)", TypeError: the JSON object must be str, not 'bytes' What should I do ? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or mute the thread .
dibgerge commented 6 years ago

Which version of python are you using?

Krasaa commented 6 years ago

I have same problem, how do you solve it? @dibgerge I 'm using python3 in win10 with jupyter notebook.

Krasaa commented 6 years ago

I find that despite the problem, the grades are updated as usual so maybe the bug can be ignored.

chrisadas commented 6 years ago

I confirm the same errors with Python 3 on Ubuntu. And that grades are registered despite the error message.

de3z1e commented 6 years ago

See pull request #11 suggesting a fix.

chrisadas commented 6 years ago

See pull request #11 suggesting a fix.

That fixed it for me.

UnnatiDhanaliya commented 5 years ago

When I try to submit first exercise to the grader I'm getting following error:


TypeError Traceback (most recent call last)

in 3 4 # send the added functions to coursera grader for getting a grade on this part ----> 5 grader.grade() ~/project/machine_learning/ml/ml-coursera-python-assignments/submission.py in grade(self) 28 # Evaluate the different parts of exercise 29 parts = OrderedDict() ---> 30 for part_id, result in self: 31 parts[str(part_id)] = {'output': sprintf('%0.5f ', result)} 32 result, response = self.request(parts) ~/project/machine_learning/ml/ml-coursera-python-assignments/Exercise1/utils.py in __iter__(self) 29 # Each part has different expected arguments/different function 30 if part_id == 1: ---> 31 res = func() 32 elif part_id == 2: 33 res = func(self.X1, self.Y1, np.array([0.5, -0.5])) TypeError: 'numpy.ndarray' object is not callable
blackhat721 commented 2 years ago

define the submission/grader object for this exercise

grader = utils.Grader() AttributeError: module 'utils' has no attribute 'Grader'