小编Bis*_*rai的帖子

无法从python访问mysql数据库

我试图通过python从mysql数据库访问数据,然后我尝试了

import MySQLdb

db = MySQLdb.connect(host = "127.0.0.1",
                     port = 3306,
                      user="Bishnu",
                      password = "Pulchowk",
                      db = "telecom_db")
cursor =db.cursor()
cursor.execute("select * from profile")
numrows = int(cursor.rowcount)
for x in range(numrows):
    row = cursor.fetchone()
    #if (row):
    print row[0], row[1]

cursor.close()

db.cose()
Run Code Online (Sandbox Code Playgroud)

然后它显示错误

Traceback (most recent call last):
  File "D:\Bishnu\BE\4th year\7th semester\Major Project I\Workspace\Bishnuji\default\first.py", line 43, in <module>
    db = "telecom_db")
  File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
TypeError: 'password' …
Run Code Online (Sandbox Code Playgroud)

python mysql mysql-python

4
推荐指数
1
解决办法
4426
查看次数

如何在javascript中获取django表单值而不将其保存到模型中

我创建了一个django表单,我不需要将这些值保存在我的数据库中.但我不知道如何在javascript中访问这些表单值.

balance.html

<script>
$(document).ready(function () {
    $('.dateinput').datepicker();
    var a = document.getElementsById("{{ form.start_date }}").val;
    alert(a);
});
</script>   

<div>
    <form action="" method="POST">{% csrf_token %} Start Date: {{ form.start_date }}&nbsp;&nbsp; End Date:{{ form.end_date }}
        <br/>
        <input type="submit" name="submit" value="See Results" id="tryonce">
    </form>
</div>
Run Code Online (Sandbox Code Playgroud)

但我无法得到结果.如何在javascript中检索这些表单值?

javascript django jquery django-forms

3
推荐指数
1
解决办法
5679
查看次数

Custom_args 在 sendgrid V3 API 中不起作用,但 unique_args 发送电子邮件,但在 event_callback 中不起作用

我使用 sendgrid v3 api 发送电子邮件。正如 V3 API 文档中提到的,我使用 custom_args 来获取事件回调中的参数,但它显示 400 个错误请求,而我使用 unique_args 时,电子邮件已发送,但事件回调不会发送我的 unique_args 参数。

data = {"content": [{"value": "dfafds", "type": "text/plain"}], "attachments": [{"content": "UEsDBB......QACAgIAAA=", "type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "content_id": "BqzZqz7LaqO9", "filename": "Contactmanager-company.xlsx", "disposition": "attachment"}], "from": {"email": "bishnusyangja@gmail.com"}, "personalizations": [{"to": [{"email": "bishnu@janakitech.com"}], "custom_args": {"email_msg_id": 106}, "subject": "daff"}]}
Run Code Online (Sandbox Code Playgroud)

来自发送网格的事件回调响应是

[{"sg_event_id": "aoDNXRAeRuaCAVRiutD-fg",
"sg_message_id": "epJqlw1JThGw--dDTC1oCQ.filter0099p3las1-8681-5B853F95-29.0",
"smtp-id": "epJqlw1JThGw--dDTC1oCQ@ismtpd0006p1maa1.sendgrid.net",
"timestamp": 1535459222,
"email": "bishnu@janakitech.com",
"event": "processed"}]
Run Code Online (Sandbox Code Playgroud)

我需要在事件回调响应中自定义参数,在此响应中我需要email_msg_id这里缺少什么?

sendgrid sendgrid-api-v3

2
推荐指数
1
解决办法
5946
查看次数

模块对象没有属性连接

我已经安装了Python 2.7和mysql-python 2.7.我想执行此代码以在Python中测试MySQL:

import MySQLdb
db = MySQLdb.connnect(host = "localhost",
                      user="Bishnu Bhattarai",
                      passwd = "password",
                      db = "student")
cursor =db.cursor()
cursor.execute("select * from basic_info" )
numrows = int(cursor.rowcount)
for x in range(0,numrows):
    row = cursor.fetchall()
    print row[0],"-->",row[1]
Run Code Online (Sandbox Code Playgroud)

但它显示错误:

Traceback (most recent call last):
  File "C:\Users\Bishnu\Desktop\database", line 2, in <module>
    db = MySQLdb.connnect(host = "localhost",
AttributeError: 'module' object has no attribute 'connnect'
Run Code Online (Sandbox Code Playgroud)

问题是什么?

mysql-python

1
推荐指数
1
解决办法
2391
查看次数

TypeError:python mysql中需要一个整数

我想在运行此代码时通过python.But简单地访问mysql数据库:

import MySQLdb
db = MySQLdb.connect(host = "127.0.0.1",
                     port = "3306",
                      user="Bishnu",
                      passwd = "Pulchowk",
                      db = "student")
cursor =db.cursor()
cursor.execute("select * from basic_info")
numrows = int(cursor.rowcount)
for x in range(0,numrows):
    row = cursor.fetchall()
    print row[0],"-->",row[1]
db.cose()
Run Code Online (Sandbox Code Playgroud)

它给出了一个错误:

Traceback (most recent call last):
  File "C:\Users\Bishnu\Desktop\database", line 6, in <module>
    db = "student")
  File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
TypeError: an integer is required
Run Code Online (Sandbox Code Playgroud)

那是什么TypeError:需要一个整数

为什么会出现这种问题 要运行此代码我有3个问题,但幸运的是这个论坛解决了我的两个问题,我认为它也将解决?

mysql-python

1
推荐指数
1
解决办法
4884
查看次数

包括额外的上下文值 django rest 框架

我正在使用 Django 休息框架。我需要传递一些额外的上下文值作为响应,但没有得到 extra_value 作为响应。

class ResultRowView(generics.ListAPIView):
    serializer_class    = ResultRowSerializer
    permission_classes  = (AccountPermission, )

    def get_serializer(self, *args, **kwargs):
        context = {'extra_value': 5000}
        return self.serializer_class(*args, context=context, **kwargs)

    def get_queryset(self):
        qs = ResultRow.objects.none()
        pk = self.kwargs.get('pk', None)
        try:
            route = IncomingRoute.objects.get(account=self.request.user.account, pk=pk)
            qs = route.app_module.rows.all()
        except Exception, e:
            print 'result_row_query: ', e
        return qs
Run Code Online (Sandbox Code Playgroud)

这里缺少什么?

python django django-rest-framework

1
推荐指数
1
解决办法
911
查看次数

使用哈希 url 响应路由器

我是新来的反应。我想将 React Router 实现为哈希 url。例如,我需要在react-router中使用#/list url,但默认情况下react使用/list url。如何在react中实现hash url?

reactjs react-router

1
推荐指数
1
解决办法
1万
查看次数