简体   繁体   English

socket.gaierror: [Errno 11001] getaddrinfo 在 django 中失败

[英]socket.gaierror: [Errno 11001] getaddrinfo failed in django

I am trying to build an ecommerce store with python and django.我正在尝试使用 python 和 django 建立一个电子商务商店。 I am currently building a pay_on_delivery option, and for that, I am sending an email to myself from the email of the user.我目前正在构建一个pay_on_delivery选项,为此,我从用户的 email 向自己发送 email。 Here is my OrderForm :这是我的OrderForm

class OrderForm(forms.Form):
    name = forms.CharField(max_length=30)
    email = forms.EmailField()
    city = forms.CharField(max_length=100)
    address = forms.CharField(widget=forms.Textarea())
    zip_code = forms.CharField(min_length=6,max_length=6)
    product = forms.CharField(max_length=200,widget=forms.TextInput(attrs={'placeholder':'Copy and paste the exact same name of the product you want to purchase'}))
    phone = forms.CharField(min_length=10,max_length=10)

    def save(self):
        cleaned_data = self.cleaned_data
        send_mail(
            "Product {cleaned_data['product']} ordered by {cleaned_data['name']}",
            "A product from our bakery has been ordered. Address: {cleaned_data['address']}. Zip code: {cleaned_data['zip']}. Phone: {cleaned_data['phone']}",
            cleaned_data["email"],
            ["rjain1807@gmail.com"],
            fail_silently=False,
        )

And my view function that handles the form submission:我认为处理表单提交的 function :

def buy(request,id):
    product = Product.objects.get(id=id)
    form = OrderForm()

    if request.method == 'POST':
        form = OrderForm(data=request.POST)
        if form.is_valid():
            form.save()
            return HttpResponse("Your order has been successfully placed!!")
    context = {
        'form':form,
        'product':product,
    }
    return render(request, 'buy_page.html',context)

Now, when I try to place an order, I get this traceback error upon the form submission:现在,当我尝试下订单时,我在提交表单时收到此回溯错误:

Internal Server Error: /products/1/buy/
Traceback (most recent call last):
  File "C:\Users\Dell\Desktop\Django\apnibakery\venv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\Dell\Desktop\Django\apnibakery\venv\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Dell\Desktop\Django\apnibakery\bakery\apnibakeryy\views.py", line 33, in buy
    form.save()
  File "C:\Users\Dell\Desktop\Django\apnibakery\bakery\apnibakeryy\forms.py", line 20, in save
    fail_silently=False,
  File "C:\Users\Dell\Desktop\Django\apnibakery\venv\lib\site-packages\django\core\mail\__init__.py", line 61, in send_mail
    return mail.send()
  File "C:\Users\Dell\Desktop\Django\apnibakery\venv\lib\site-packages\django\core\mail\message.py", line 284, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "C:\Users\Dell\Desktop\Django\apnibakery\venv\lib\site-packages\django\core\mail\backends\smtp.py", line 102, in send_messages
    new_conn_created = self.open()
  File "C:\Users\Dell\Desktop\Django\apnibakery\venv\lib\site-packages\django\core\mail\backends\smtp.py", line 62, in open
    self.connection = self.connection_class(self.host, self.port, **connection_params)
  File "C:\Users\Dell\AppData\Local\Programs\Python\Python37\lib\smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "C:\Users\Dell\AppData\Local\Programs\Python\Python37\lib\smtplib.py", line 336, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "C:\Users\Dell\AppData\Local\Programs\Python\Python37\lib\smtplib.py", line 307, in _get_socket
    self.source_address)
  File "C:\Users\Dell\AppData\Local\Programs\Python\Python37\lib\socket.py", line 707, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "C:\Users\Dell\AppData\Local\Programs\Python\Python37\lib\socket.py", line 752, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

What is wrong here?这里有什么问题?

It seems like you are not able to resolve the hostname.您似乎无法解析主机名。 What EMAIL_HOST and EMAIL_PORT do you have set in your Django settings?您在 Django 设置中设置了哪些EMAIL_HOST和 EMAIL_PORT? Make sure you can resolve the hostname properly, by entering those infos in this simple script:通过在这个简单的脚本中输入这些信息,确保您可以正确解析主机名:

import socket
socket.getaddrinfo('yourhostname.com', 80)

I was too confronting the same error for a whole day even though i tried to fix it out then, fortunately, I got to know that, It might have occurred due to one of these errors.即使我当时试图修复它,我也面对同样的错误一整天,幸运的是,我知道,它可能是由于其中一个错误而发生的。

  1. Server error服务器错误
  2. Unstable internet connection.不稳定的互联网连接。

In my case, i encountered case 2 then fixed it.就我而言,我遇到了案例 2,然后修复了它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 socket.gaierror:[Errno 11001] getaddrinfo 失败 - socket.gaierror: [Errno 11001] getaddrinfo failed (Python)socket.gaierror:[Errno 11001] getaddrinfo失败 - (Python) socket.gaierror: [Errno 11001] getaddrinfo failed Scapy导入错误'socket.gaierror:[Errno 11001] getaddrinfo失败' - Scapy import error 'socket.gaierror: [Errno 11001] getaddrinfo failed' 错误:- socket.gaierror:[Errno 11001] getaddrinfo 在获取请求中失败 - Error :- socket.gaierror: [Errno 11001] getaddrinfo failed in get request 如何解决:socket.gaierror: [Errno 11001] getaddrinfo failed - How to solve: socket.gaierror: [Errno 11001] getaddrinfo failed gaierror socket.gaierror: [Errno 11001] getaddrinfo 失败 mail.send(msg) - gaierror socket.gaierror: [Errno 11001] getaddrinfo failed mail.send(msg) 当我在 python 中使用套接字模块时,我收到此错误:'socket.gaierror: [Errno 11001] getaddrinfo failed' - I get this error:' socket.gaierror: [Errno 11001] getaddrinfo failed' when I use the socket module in python socket.gaierror:[Errno 11003] getaddrinfo失败 - socket.gaierror: [Errno 11003] getaddrinfo failed socket.gaierror: [Errno 11001] getaddrinfo failed" in python,同时使用简单的自定义 web 浏览器 - socket.gaierror: [Errno 11001] getaddrinfo failed" in python, while using a simple custom web browser Flask-Mail 显示 socket.gaierror: [Errno 11001] getaddrinfo failed - Flask-Mail showing socket.gaierror: [Errno 11001] getaddrinfo failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM