I Have a Problem with Sending Mail:Typeerror: _Init_() Got an Unexpected Keyword Argument 'Context'

TypeError: __init__() got an unexpected keyword argument 'providing_args'

Based on the comments, you're running Django 4.0 with an old version of AllAuth. So you just need to update AllAuth and should be fine.


However, other people who have upgraded AllAuth and are running Django 4.0 but still seeing this error may have custom AllAuth or other signals registered that include the providing_args argument.

In this case, you need to search your project for any signals (such as those often overridden in AllAuth: user_logged_in or email_changed) and remove the providing_args=['request', 'user', 'signup'] or other variation from the Signal parenthesis.

See below for more information, and an example diff showing how you could move each providing_args argument to a commented line.


Django deprecated the ability to use the providing_args argument to django.dispatch.Signal in Django 3.1. See bullet in the Misc section of the 3.1 release notes.

It was removed because this argument doesn't do anything other than act as documentation. If that seems strange, it is because it is strange. Arguments should indicate data getting passed. This is probably why it was deprecated.

Django 4.0 went ahead and removed this altogether, making any code that calls Signal() with the providing_args argument now trigger the TypeError you encountered:

TypeError: Signal.__init__() got an unexpected keyword argument 'providing_args'

AllAuth removed the use of this argument in September of 2020. (See original report on this issue here and the referenced diff)

The person asking the question in this thread was running AllAuth 0.42.0 which does not include this change and is thus incompatible with Django 4.0.

As of today, the last version of Django AllAuth 0.42.0 is compatible with is Django 3.2.9.

__init__() got an unexpected keyword argument 'user'

You can't do

LivingRoom.objects.create(user=instance)

because you have an __init__ method that does NOT take user as argument.

You need something like

#signal function: if a user is created, add control livingroom to the user    
def create_control_livingroom(sender, instance, created, **kwargs):
if created:
my_room = LivingRoom()
my_room.user = instance

Update

But, as bruno has already said it, Django's models.Model subclass's initializer is best left alone, or should accept *args and **kwargs matching the model's meta fields.

So, following better principles, you should probably have something like

class LivingRoom(models.Model):
'''Living Room object'''
user = models.OneToOneField(User)

def __init__(self, *args, temp=65, **kwargs):
self.temp = temp
return super().__init__(*args, **kwargs)

Note - If you weren't using temp as a keyword argument, e.g. LivingRoom(65), then you'll have to start doing that. LivingRoom(user=instance, temp=66) or if you want the default (65), simply LivingRoom(user=instance) would do.

How to fix 'TypeError: __init__() got an unexpected keyword argument 'sender''

You are supposed to pass a Message model instance to MessageSerializer or a dict containing data with the keys specified in fields.

In case you want to pass a dict, pass the dict to data keyword.

message_dict = {'sender': request.user, 'chat_room': ChatRoom.objects.get(id=request.data['chat_room_id']), 'content': MessageContent(text=request.data['text'])}
message_serializer = MessageSerializer(data=message_dict)

if message_serializer.is_valid():
message_serializer.save()

Make sure you have create method implemented in your MessageSerializer.

Python Pydantic Error: TypeError: __init__() takes exactly 1 positional argument (2 given)

You have to give Pydantic which key you are providing a value for:

token_data = schemas.TokenData(username=username)

Otherwise Pydantic has no idea that the variable username from the parent scope should be assigned to the username property in the schema.

Why I get an error when adding __init__(self) method to Django rest framework viewset class?

The “got an unexpected keyword argument” exception is rather descriptive. What it means is your class instance (in this case, your ViewSet instance) was initialized with a keyword argument that you’re not handling. That can be fixed by doing the following in your init method:

def __init__(self, **kwargs):
# self.instrument_service = InstrumentsService()
# self.instruments = Instrument.objects.all()
super().__init__(**kwargs)

This is required because the super class (View) utilizes **kwargs when the instance is initialized.

For the record, this is not using Django as it was intended. Django was never meant for service layers and using the init method like this is counterproductive since a ViewSet takes a queryset variable. I would encourage you to read the documentation much more thoroughly before continuing with this project of yours.

__init__() missing 1 required positional argument

You're receiving this error because you did not pass a data variable to the DHT constructor.

aIKid and Alexander's answers are nice but it wont work because you still have to initialize self.data in the class constructor like this:

class DHT:
def __init__(self, data=None):
if data is None:
data = {}
else:
self.data = data
self.data['one'] = '1'
self.data['two'] = '2'
self.data['three'] = '3'
def showData(self):
print(self.data)

And then calling the method showData like this:

DHT().showData()

Or like this:

DHT({'six':6,'seven':'7'}).showData()

or like this:

# Build the class first
dht = DHT({'six':6,'seven':'7'})
# The call whatever method you want (In our case only 1 method available)
dht.showData()

How to run a http server which serves a specific path?

In Python 3.7 SimpleHTTPRequestHandler can take a directory argument:

import http.server
import socketserver

PORT = 8000
DIRECTORY = "web"

class Handler(http.server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory=DIRECTORY, **kwargs)

with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()

and from the command line:

python -m http.server --directory web

To get a little crazy... you could make handlers for arbitrary directories:

def handler_from(directory):
def _init(self, *args, **kwargs):
return http.server.SimpleHTTPRequestHandler.__init__(self, *args, directory=self.directory, **kwargs)
return type(f'HandlerFrom<{directory}>',
(http.server.SimpleHTTPRequestHandler,),
{'__init__': _init, 'directory': directory})

with socketserver.TCPServer(("", PORT), handler_from("web")) as httpd:
print("serving at port", PORT)
httpd.serve_forever()


Related Topics



Leave a reply



Submit