Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

用ip访问可以,但用域名访问就报错 #1287

Closed
Howardnm opened this issue Jul 9, 2021 · 4 comments
Closed

用ip访问可以,但用域名访问就报错 #1287

Howardnm opened this issue Jul 9, 2021 · 4 comments

Comments

@Howardnm
Copy link

Howardnm commented Jul 9, 2021

环境

  • 系统/平台: centos 7 docker

  • nodejs 版本: 14.17.2

  • API版本: 4.0.16

出现问题

http://外网ip:3000/浏览器访问没问题
但是用域名访问就出错,http://域名:3000/浏览器访问结果如下:

URIError: URI malformed
    at decodeURIComponent (<anonymous>)
    at /app/app.js:47:7
    at Array.forEach (<anonymous>)
    at /app/app.js:43:48
    at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
    at /app/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
    at next (/app/node_modules/express/lib/router/index.js:275:10)
    at /app/app.js:37:54

期待效果

希望自动解析域名

@Howardnm
Copy link
Author

Howardnm commented Jul 9, 2021

问题已自己解决,采用python进行域名转ip,但还是希望直接支持域名吧,少走弯路。

域名转ip,方法如下:

import socket
result = socket.getaddrinfo("www.baidu.com", None)  # 填自己的服务器域名
url='http://' + result[0][4][0] + ':3000/playlist/detail?id=3168324249'

实例:

## python 3
import urllib.request
import urllib.parse
import json
import socket

result = socket.getaddrinfo("www.baidu.com", None)  # 填自己的服务器域名
url='http://' + result[0][4][0] + ':3000/playlist/detail?id=3168324249'
get1, get2, get3="playlist", "tracks", "name"

# 对url进行网页爬取
headers={
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36'}
request=urllib.request.Request(url=url, headers=headers)
response=urllib.request.urlopen(request)

# 对网页内容进行处理
ls = response.read().decode('utf8')
json_data=json.loads(ls)
data=json_data.get(get1).get(get2)
result1=[]
for i in data:
    result1.append(i.get(get3))

# 输出txt歌单
fo=open("songlist-songname.txt", "w", encoding='utf8')
for line in result1:
    fo.write(line + '\n')
fo.close()

@greenhat616
Copy link
Contributor

这个是 URI 解析的问题,应该是参数有非法字符,有没有复现的 sample,我做个 PR 吧

@Howardnm
Copy link
Author

经过多个域名测试:
腾讯云域名(.top)和oray子域名(.net),没问题
昨天只测试了群辉提供的子域名"xxx.synology.me",就出现了URIError

@greenhat616
Copy link
Contributor

image
这个应该是处理 cookie 时出现了错误,你那边能不能发一份脱敏后的 请求 headers 呢

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants