安卓qpython向ksweb服务器post文件失败

2401_86071404 2024-12-07 21:23:13

需求背景:
安卓本地安装了ksweb,qpython。ksweb开服务器,qpython向这个服务器文件夹周期性的发送日历文件,以取得一个可以连接到该文件的url,然后用小米自带的日历应用订阅这个url实现动态日历。
ksweb的服务器为lighttpd,其实就是默认的welcome的页面的端口,文件夹为htdocs。qpython使用的是request post功能,将文件发送到htdocs 端口下的文件夹。

程序本身跑起来没报错,但是程序跑完服务器文件夹里没文件。status code 200,response text看了一下应该没什么问题,起码说明与服务器连接良好。但是这个文件就是传不进去。ksweb qpython都是满权限。
上传代码:

#保存ics程序
def Ics_saver():
    output_path_str="/storage/emulated/0/Download/myics.ics"
    with open(output_path_str,'w') as f:
         f.writelines(cal.serialize_iter())
         upload_url='http://localhost:8080/ics'
    file={'file':open(output_path_str,'rb')}
    response_upload=requests.post(upload_url,files=file)
    print(response_upload.status_code)

从代码看得出来我是先把一个日历文件保存到本地(这个其实没问题,我已经跑通了)。然后我把这个文件再提交到8080端口ics文件夹里。目前就是不明白为什么这个文件为什么进不了服务器文件夹
试过直接把文件保存到htdocs,但是显示没有权限,我理解因为这个文件夹被服务器占用,不能更改,所以想到用python request post进行上传,照道理lighttpd服务器默认可以post到服务器里的,但即使代码显示ok,实际上这个文件也没进去。

服务器配置文件详情

## !!!WARNING!!!
## Be careful changing this configuration file!
## Some changes may result in incorrect function of the program.
## Always make backups of configuration files before any changes.
## --------------------------------------------------------------
 
########
#For the proper functioning of KSWEB keep this settings at the top of this file
 
#begin_docroot (do not remove this label!)
server.document-root = "/mnt/sdcard/htdocs"
#end_docroot (do not remove this label!)
 
#begin_port (do not remove this label!)
server.port = "8080"
#end_port (do not remove this label!)
 
#begin_hosts (do not remove this label!)
include "/data/user/0/ru.kslabs.ksweb/components/lighttpd/conf/localhost_host.conf"
#end_hosts (do not remove this label!)
########
 
#debug.log-request-header     = "enable"
#debug.log-response-header    = "enable"
#debug.log-request-handling   = "enable"
#debug.log-file-not-found     = "enable"
#debug.log-condition-handling = "enable"
 
 
server.errorlog = "/mnt/sdcard/ksweb/log/lighttpd/lighttpd.log"
dir-listing.activate = "enable"
 
index-file.names = ("index.php", "index.html")
 
fastcgi.server = ( ".php" =>
    ((
        "socket" => "/data/data/ru.kslabs.ksweb/php.sock"
    ))
)
 
#fastcgi.server = ( ".php" =>
#  ((
#    "host" => "127.0.0.1",
#    "port" => 9001
#  ))
#)
 
server.max-keep-alive-requests = 10
server.max-keep-alive-idle = 10
server.max-read-idle = 10
server.max-write-idle = 30
server.max-connections = 512
server.kbytes-per-second = 8192
connection.kbytes-per-second = 8192
server.protocol-http11 = "enable"
 
#auth.debug = 2
auth.backend = "plain"
 
##  MimeType handling
## -------------------
##
## Use the "Content-Type" extended attribute to obtain mime type if
## possible
##
mimetype.use-xattr        = "disable"
 
##
## mimetype mapping
##
mimetype.assign             = (
  ".appcache"     =>      "text/cache-manifest",    
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".spec"         =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar",
  ".odt"          =>      "application/vnd.oasis.opendocument.text",
  ".ods"          =>      "application/vnd.oasis.opendocument.spreadsheet",
  ".odp"          =>      "application/vnd.oasis.opendocument.presentation",
  ".odg"          =>      "application/vnd.oasis.opendocument.graphics",
  ".odc"          =>      "application/vnd.oasis.opendocument.chart",
  ".odf"          =>      "application/vnd.oasis.opendocument.formula",
  ".odi"          =>      "application/vnd.oasis.opendocument.image",
  ".odm"          =>      "application/vnd.oasis.opendocument.text-master",
  ".ott"          =>      "application/vnd.oasis.opendocument.text-template",
  ".ots"          =>      "application/vnd.oasis.opendocument.spreadsheet-template",
  ".otp"          =>      "application/vnd.oasis.opendocument.presentation-template",
  ".otg"          =>      "application/vnd.oasis.opendocument.graphics-template",
  ".otc"          =>      "application/vnd.oasis.opendocument.chart-template",
  ".otf"          =>      "application/vnd.oasis.opendocument.formula-template",
  ".oti"          =>      "application/vnd.oasis.opendocument.image-template",
  ".oth"          =>      "application/vnd.oasis.opendocument.text-web",
  ".webm"         =>      "video/webm",
  ".weba"         =>      "audio/webm",
  ".svg"          =>      "image/svg+xml",
 
# make the default mime type application/octet-stream.
  ""              =>      "application/octet-stream",
)
 
#file upload
server.max-request-size = 1000000
#server.network-backend = "writev"
server.upload-dirs =( "/htdocs/ics" )
 
 
 
server.modules = ( 
    "mod_rewrite", 
    "mod_redirect", 
    "mod_alias",
#    "mod_extforward",
    "mod_access",
    "mod_auth", 
    "mod_authn_file",
    "mod_flv_streaming",
    "mod_indexfile",
    "mod_userdir",
    "mod_dirlisting",
    "mod_evhost",
    "mod_secdownload",
#    "mod_staticfile",
    "mod_compress",
    "mod_accesslog",
    "mod_status", 
    "mod_setenv",
    "mod_fastcgi",
    "mod_proxy",
    "mod_simple_vhost",
    "mod_cgi",
    "mod_ssi",
    "mod_usertrack",
    "mod_expire",
    "mod_webdav",
   "mod_upload",
   "mod_magnet" 
)
 

 

...全文
308 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

80,473

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧