我需要使用查询字符串发出请求,例如Dim iRet As Integer
Dim strPrompt As String
Dim strTitle As String
' Promt
strPrompt = "Please select the last Kronos Full File before the dates of this HCM Report." & vbCrLf & _
"This will be used to find the Old Position, Org Unit, and Old Cost Center." & vbCrLf & _
"For example, if the date of this report is 7-28-17 thru 8-25-17, the closest Kronos Full File you would want to use is 7-27-17."
' Dialog's Title
strTitle = "Last Kronos Full File for Old Positions"
'Display MessageBox
iRet = MsgBox(strPrompt, vbOK, strTitle)
Dim LR As Long
Dim X As String
Dim lNewBracketLocation As Long
X = Application.GetOpenFilename( _
FileFilter:="Excel Files (*.xls*),*.xls*", _
Title:="Choose the Kronos Full File.", MultiSelect:=False)
MsgBox "You selected " & X
'Find the last instance in the string of the path separator "\"
lNewBracketLocation = InStrRev(X, Application.PathSeparator)
'Edit the string to suit the VLOOKUP formula - insert "["
X = Left$(X, lNewBracketLocation) & "[" & Right$(X, Len(X) - lNewBracketLocation)
shtName = ActiveWorkbook.Worksheets(1).name
LR = Range("E" & Rows.Count).End(xlUp).Row
Range("T2").Formula = "=VLOOKUP($E2,'" & X & "]shtName'!$B$1:$AP$99999,15,0)"
Stop
Range("T2").AutoFill Destination:=Range("T2:T" & Range("E" & Rows.Count).End(xlUp).Row)
Stop
Range("T2:T" & Range("E" & Rows.Count).End(xlUp).Row).Select
Stop
Range("U2").Formula = "=VLOOKUP($E2,'" & X & "]shtName'!$B$1:$AP$99999,41,0)"
Range("U2").AutoFill Destination:=Range("U2:U" & Range("E" & Rows.Count).End(xlUp).Row)
Range("U2:U" & Range("E" & Rows.Count).End(xlUp).Row).Select
Range("V2").Formula = "=VLOOKUP($E2,'" & X & "]shtName'!$B$1:$AP$99999,18,0)"
Range("V2").AutoFill Destination:=Range("V2:V" & Range("E" & Rows.Count).End(xlUp).Row)
Range("V2:V" & Range("E" & Rows.Count).End(xlUp).Row).Select
Cells.Select
Cells.EntireColumn.AutoFit
,但是当我在请求参数(?where[id]=CXP
)中定义它时,请求会返回内部服务器错误params = {'where[id]': 'CXP'}
。
500
提出此请求的正确意见是什么?
感谢。
答案 0 :(得分:0)
服务器很可能需要json格式化。虽然500
看起来不像那样,但仍值得一试。
从请求版本2.4.2开始,您可以简单地使用json作为参数。它将为您处理编码。您所需要做的就是:
r = requests.get('http://myurl', json=params)
如果您(无论出于何种原因)使用旧版本的请求,您可以尝试以下操作:
import simplejson as json
r = requests.get('http://myurl', param=json.loads(params))
我总是建议simplejson
超过json
包,因为它会更频繁地更新。
编辑:如果你想阻止urlencoding,你唯一的解决方案可能是传递一个字符串。
r = requests.get('http://myurl', param='where[id]=CXP')
答案 1 :(得分:0)
朋友......我想我解决了。
params 允许请求中的字符串。 所以,我认为这不是最好的方式,但我把它当作:
r = requests.get('http://myurl',params ='where [service] = CXP')
工作正常!