Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python web爬网,requests.post不会返回服务器环境中的任何内容_Python_Json_Http_Request_Web Crawler - Fatal编程技术网

python web爬网,requests.post不会返回服务器环境中的任何内容

python web爬网,requests.post不会返回服务器环境中的任何内容,python,json,http,request,web-crawler,Python,Json,Http,Request,Web Crawler,我正在尝试在web中抓取csv文件。 在网页中下载文件是有效的。此外,此代码在本地环境(Windows)中运行良好。 但是,当我在服务器环境(Ubuntu)中执行代码时,它不会返回任何内容,如下所示。我怎样才能解决这个问题?我想不出是什么问题 def get_otp(bld, date): url="http://marketdata.krx.co.kr/contents/COM/GenerateOTP.jspx" header={'Referer': 'ht

我正在尝试在web中抓取csv文件。 在网页中下载文件是有效的。此外,此代码在本地环境(Windows)中运行良好。 但是,当我在服务器环境(Ubuntu)中执行代码时,它不会返回任何内容,如下所示。我怎样才能解决这个问题?我想不出是什么问题

def get_otp(bld, date):
    url="http://marketdata.krx.co.kr/contents/COM/GenerateOTP.jspx"
    header={'Referer': 'http://marketdata.krx.co.kr/mdi', "User-Agent": "Mozilla/5.0",
            "X-Requested-With": "XMLHttpRequest"}
    bld= "MKD/13/1302/13020101/mkd13020101"
    param={"name": "fileDown", "filetype" : "csv", "url": bld, "market_gubun": 'ALL', 
           "sect_tp_cd": "ALL","schdate": date, 
           "pagePath": "/contents/MKD/13/1302/13020101/MKD13020101.jsp"}
    return requests.get(url, headers=header, params=param).text

def get_file(otp):
    url="http://file.krx.co.kr/download.jspx?"
    header={"Origin": "http://marketdata.krx.co.kr",
            'Referer': 'http://marketdata.krx.co.kr/mdi',
            "Upgrade-Insecure-Requests": "1",
            "Host": "file.krx.co.kr",
            "User-Agent": "Mozilla/5.0"}
    param={'code':otp}
    byte_data = requests.post(url, headers=header, data=param)
    data=byte_data
    #df = pd.read_csv(BytesIO(byte_data))
    return data
结果

{'Date': 'Thu, 19 Nov 2020 08:37:01 GMT', 
'Set-Cookie': 'SCOUTER=z368kb97coovj; Expires=Tue, 07-Dec-2088 11:51:08 GMT, JSESSIONID=9AC74CC81C757D3CD656EA4FD0D3A05D.102tomcat4; Path=/; HttpOnly',
 'Content-Length': '0', 
'Content-Type': 'text/html;charset=UTF-8'}
{'Date': 'Thu, 19 Nov 2020 08:37:01 GMT', 
'Set-Cookie': 'SCOUTER=z368kb97coovj; Expires=Tue, 07-Dec-2088 11:51:08 GMT, JSESSIONID=9AC74CC81C757D3CD656EA4FD0D3A05D.102tomcat4; Path=/; HttpOnly',
 'Content-Length': '0', 
'Content-Type': 'text/html;charset=UTF-8'}