upbit / pixivpy

Pixiv API for Python
https://pypi.org/project/PixivPy3/#files
The Unlicense
1.79k stars 149 forks source link

auth接口返回400 #92

Closed dylech30th closed 5 years ago

dylech30th commented 5 years ago

吃饭前还好好的,吃饭后突然就变成400了

POST /auth/token HTTP/1.1
Host: oauth.secure.pixiv.net
X-Client-Time: 2019-10-24T20:32:10.398123
X-Client-Hash: 6127c8d82dea196182a07c4ef31f3786
Content-Type: application/x-www-form-urlencoded
User-Agent: PixivAndroidApp/5.0.64 (Android 6.0)

username={我的邮箱}&password={我的密码}&grant_type=password&client_id=MOBrBDS8blbauoSck0ZfDbtuzpyT&client_secret=lsACyCD94FhDUtGTXi3QzcFE2uU1hqtDaKeqrdwj&get_secure_url=1

返回结果:

{
    "has_error": true,
    "errors": {
        "system": {
            "message": "access_denied",
            "code": 1508
        }
    }
}
rainyroads commented 5 years ago

Same here, started getting this error today.

pixivpy3.utils.PixivError: [ERROR] auth() failed! check username and password.
HTTP 400: {"has_error":true,"errors":{"system":{"message":"access_denied","code":1508}}}

Username and password are correct.

AricStewart commented 5 years ago

I am seeing this exact error as well

dylech30th commented 5 years ago

I am seeing this exact error as well

Same here, started getting this error today.

pixivpy3.utils.PixivError: [ERROR] auth() failed! check username and password.
HTTP 400: {"has_error":true,"errors":{"system":{"message":"access_denied","code":1508}}}

Username and password are correct.

every projects I know (include myself's) that based on this auth api have the same problem so I think it probably not my problem but api's

rainyroads commented 5 years ago

Yeah, looks like something will need to be updated to be compliant with whatever changed in the API.

Hopefully it's nothing too difficult.

Mikubill commented 5 years ago

验证的时候生成的X-Client-Hash和X-Client-Time不匹配,改一下local_time的格式就好啦(w 测试修改以后可以正常登录。

change this: https://github.com/upbit/pixivpy/blob/0ca6d7495add5b0cf338ae623a52f2b8a1c2d11e/pixivpy3/api.py#L84 to

local_time = datetime.utcnow().strftime( '%Y-%m-%dT%H:%M:%S+00:00' )

相关细节

对 pixiv_v5.0.166 进行反编译

./sources/p139jp/pxv/android/p192c/C4424g.java 有字符串生成和请求构造相关的内容:

String format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ", Locale.US).format(new Date());
StringBuilder sb = new StringBuilder();
sb.append(format);
sb.append("28c1fdd170a5204386cb1313c7077b34f83e4aaf4aa829ce78c231e05b0bae2c");
Request build = chain.request().newBuilder().addHeader(C3376a.HEADER_USER_AGENT, C4419d.f15143a).addHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8").addHeader(str2, Locale.getDefault().toString()).addHeader("App-OS", C3376a.ANDROID_CLIENT_TYPE).addHeader(str3, VERSION.RELEASE).addHeader("App-Version", "5.0.166").addHeader("X-Client-Time", format).addHeader("X-Client-Hash", C4469d.m14047a(sb.toString())).build();

./sources/p139jp/pxv/android/account/C3984a.java 有两个secret对应的值

PixivOAuthResponse b = C4425h.m13976a(C4425h.f15154f).mo22048b("MOBrBDS8blbauoSck0ZfDbtuzpyT", "lsACyCD94FhDUtGTXi3QzcFE2uU1hqtDaKeqrdwj", "password", str2, password, ((C5687a) this.f13877b.mo24141a()).mo23205a(), true, true);

./sources/p139jp/pxv/android/p192c/C4425h.java 有header构造相关内容

PixivOAuthResponse mo22048b(@C6525c(mo25561a = "client_id") String str, @C6525c(mo25561a = "client_secret") String str2, @C6525c(mo25561a = "grant_type") String str3, @C6525c(mo25561a = "username") String str4, @C6525c(mo25561a = "password") String str5, @C6525c(mo25561a = "device_token") String str6, @C6525c(mo25561a = "get_secure_url") boolean z, @C6525c(mo25561a = "include_policy") boolean z2);

Auth Header为(暂时没有Android设备,用iOS做了测试)

App-OS: ios
App-OS-Version: 13.1.2
App-Version: 7.7.6
X-Client-Time: 2019-10-25T08:*:*+08:00
X-Client-Hash: 21065295cbbe1b*
User-Agent: PixivIOSApp/7.7.6 (iOS 13.1.2; iPhone11,8)

Auth body为

client_id: "MOBrBDS8blbauoSck0ZfDbtuzpyT",
client_secret: "lsACyCD94FhDUtGTXi3QzcFE2uU1hqtDaKeqrdwj",
grant_type: "password",
username: *,
password: *,
device_token: *,
get_secure_url: "true",
include_policy: "true",
dylech30th commented 5 years ago

验证的时候生成的X-Client-Hash和X-Client-Time不匹配,改一下local_time的格式就好啦(w 目前测试修改以后可以正常登录。

change this: https://github.com/upbit/pixivpy/blob/0ca6d7495add5b0cf338ae623a52f2b8a1c2d11e/pixivpy3/api.py#L84

to

local_time = datetime.utcnow().strftime( '%Y-%m-%dT%H:%M:%S+00:00' )

...then login.

emm等于说p站重新设置了X-Client-Time的格式吗emmm,这理由还蛮汗的(x

dylech30th commented 5 years ago

Yeah, looks like something will need to be updated to be compliant with whatever changed in the API.

Hopefully it's nothing too difficult.

see @Mikubill 's answer, you can change the code that generate the local_time to local_time = datetime.utcnow().strftime( '%Y-%m-%dT%H:%M:%S+00:00' ) to fix this problem, I just tried it and works fine for me :D

emesh0620 commented 5 years ago

I haven't been able to access pixiv for about 12 hours with the following error message (When started with VSCODE). Please take care of it as soon as possible.

pixivpy3.utils.PixivError: [ERROR] auth() failed! check username and password. HTTP 400: {"has_error":true,"errors":{"system":{"message":"access_denied","code":1508}}}

upbit commented 5 years ago

Merged #93 . Try install master from source to fix this

git clone https://github.com/upbit/pixivpy.git
cd pixivpy/
pip uninstall pixivpy
pip install .
dylech30th commented 5 years ago

I haven't been able to access pixiv for about 12 hours with the following error message (When started with VSCODE). Please take care of it as soon as possible.

pixivpy3.utils.PixivError: [ERROR] auth() failed! check username and password. HTTP 400: {"has_error":true,"errors":{"system":{"message":"access_denied","code":1508}}}

read replies above, this problem has been solved

upbit commented 4 years ago

Sorry for the late reply, please update to v3.5.1 to resolve this issue.

dylech30th commented 4 years ago

p139jp

说起来反编译时候是怎么解决混淆问题的...我反编译之后得到的都是一大堆混淆过的class