PyCharm中发现模块引用老是有各种问题

可以用映射来解决,例如需要调用登录模块里面的东西的时,可以这样处理:

登录模块:1-login.py

import this
import requests
import json
import unittest
import HTMLTestRunner yuming='http://test-a.==.cn' '''登录'''
s=requests.session()
def login(phone):
headers54 = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Referer': '{0}/systLogonUser/login.do'.format(yuming)}
url54='{0}/systLogonUser/adminLogon.do'.format(yuming)
data54 ={
'userName':phone,
'pwd':'123456Aa',
'verifyCode':121
}
r=s.post(url=url54,data=data54,headers=headers54)
login_response=r.text
login_statuscode=r.status_code
print(login_statuscode, login_response, s)
return login_statuscode,login_response,s login(18200717108)

在后面的一个接口中进行调用:

''' 
用户登录状态
这里用到了登录接口中的yuming、s
'''
print('*'*100,'\n','/personal/bala','\n','*'*100)
url='{0}/personal/bala?_=1556108604971'.format(f.yuming)
r=f.s.get(url=url,headers=headers11)
print(r.status_code)
print(r.text)

未登录与登录后返回的结果不同:

****************************************************************************************************
/personal/bala
****************************************************************************************************
200
{"time":"","code":"","msg":"未登录"}
****************************************************************************************************
/personal/bala
****************************************************************************************************
200
{"time":"","accountBala":"8210100.80","usableBala":"7543000.80","frozenBala":"667100.00","code":"","msg":"OK"}
Process finished with exit code 0
05-11 21:53
查看更多