通过python脚本

时间:2017-12-06 09:30:24

标签: python sql-server apache github pypyodbc

从以下配置开始,我应该使用什么配置来连接Apache:

SERVER    :   DESKTOP-C6RS3DO
User Name :   (Default:blank)
Password  :   (Default:blank)
Connection:   DESKTOP-C6RS3DO\Vitriv-Desktop

即使服务器身份验证也设置为“SQL Server和Windows身份验证模式”

cnxn = pypyodbc.connect(driver='{ODBC Driver 13 for SQL Server}', server='DESKTOP-C6RS3DO', database='demo2016', Trusted_Connection='Yes')

cnxn = pypyodbc.connect(
    r'DRIVER={ODBC Driver 13 for SQL Server};'
    r'SERVER=DESKTOP-C6RS3DO;'
    r'DATABASE=demo2016;'
    #r'UID=Vitriv-Desktop;'
    #r'PWD='
    r'Trusted_Connection=yes;'
    )

errors.log

[Wed Dec 06 14:40:05.679511 2017] [cgi:error] [pid 5592:tid 1340] [client ::1:52581] AH01215: 

Traceback (most recent call last):\r: C:/Apache24/htdocs/vitriv.py, referer: http://localhost/signup_page.html
   File "C:/Apache24/htdocs/vitriv.py", line 37, in <module>\r: C:/Apache24/htdocs/vitriv.py, referer: http://localhost/signup_page.html
     r'DRIVER={ODBC Driver 13 for SQL Server};'\r: C:/Apache24/htdocs/vitriv.py, referer: http://localhost/signup_page.html
   File "C:/Users/Vitriv-Desktop/AppData/Local/Programs/Python/Python36-32/Lib/site-packages\\pypyodbc.py", line 2454, in __init__\r: C:/Apache24/htdocs/vitriv.py, referer: http://localhost/signup_page.html
     self.connect(connectString, autocommit, ansi, timeout, unicode_results, readonly)\r: C:/Apache24/htdocs/vitriv.py, referer: http://localhost/signup_page.html
   File "C:/Users/Vitriv-Desktop/AppData/Local/Programs/Python/Python36-32/Lib/site-packages\\pypyodbc.py", line 2507, in connect\r: C:/Apache24/htdocs/vitriv.py, referer: http://localhost/signup_page.html
     check_success(self, ret)\r: C:/Apache24/htdocs/vitriv.py, referer: http://localhost/signup_page.html
   File "C:/Users/Vitriv-Desktop/AppData/Local/Programs/Python/Python36-32/Lib/site-packages\\pypyodbc.py", line 1009, in check_success\r: C:/Apache24/htdocs/vitriv.py, referer: http://localhost/signup_page.html
     ctrl_err(SQL_HANDLE_DBC, ODBC_obj.dbc_h, ret, ODBC_obj.ansi)\r: C:/Apache24/htdocs/vitriv.py, referer: http://localhost/signup_page.html
   File "C:/Users/Vitriv-Desktop/AppData/Local/Programs/Python/Python36-32/Lib/site-packages\\pypyodbc.py", line 987, in ctrl_err\r: C:/Apache24/htdocs/vitriv.py, referer: http://localhost/signup_page.html
     raise DatabaseError(state,err_text)\r: C:/Apache24/htdocs/vitriv.py, referer: http://localhost/signup_page.html
 pypyodbc.DatabaseError: ('28000', "[28000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'WORKGROUP\\\\DESKTOP-C6RS3DO$'.")\r: C:/Apache24/htdocs/vitriv.py, referer: http://localhost/signup_page.html

通过python shell连接成功但不通过Web浏览器执行。为什么呢?

1 个答案:

答案 0 :(得分:0)

ANSWER

@pytest.mark.parametrize('credentials, return_code', [
  ('user1', 200),
  ('user2', 200),
  ('user3', 401),
], indirect=True)
def test_login(credentials, return_code):
    return True