Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter yasu7

    (@yasu7)

    Hi @amieiro

    Thank you very much for your support. After changing the WordPress settings, the program ran successfully.

    Thread Starter yasu7

    (@yasu7)

    Hi @amieiro

    Thank you very much for all your help!
    
    >Can you get more information from this screenshot?
    thank you. Unfortunately, I wasn't able to get more information.
    
    
    >Could be related with your ISP or your hosting, making some additional block?
    I've done a lot of research, but I'm not sure why I'm getting a 403. I have checked the following settings, but is there anything else I should check?(What is your permalink setting?, etc)
    ・Application password is already set
    ・Restrictions on access to “WordPress REST API” from foreign IP addresses have been disabled
    
    
    Also, to solve the problem, I changed the program as follows and tried to run it. Do you have any clues?
    
    --------------- changed program ----------------------
    import requests
    
    url = 'https://YYYYYYY.wp.xdomain.jp/wp-json/wp/v2/posts/'
    headers = {'Content-Type': 'application/json'}
    auth = ('YYYYYYY', 'XXXX XXXX XXXX XXXX XXXX XXXX')
    data = {
        'title': 'Test title',
        'content': 'Test content',
        'status': 'publish',
        'slug': 'test-title'
    }
    
    response = requests.post(url, headers=headers, auth=auth, json=data)
    
    print("Response status code:", response.status_code)
    print("Response headers:", response.headers)
    print("Response text:")
    print(response.text)
    
    ---------------------------------------------------------
    
    
    ----------------Result-----------------------
    Response status code: 403
    Response headers: {'Connection': 'Keep-Alive', 'Keep-Alive': 'timeout=5, max=100', 'content-type': 'text/html; charset=UTF-8', 'last-modified': 'Fri, 21 Oct 2022 03:32:47 GMT', 'etag': '"b1b-635212df-b0abf8cad2eb7094;br"', 'accept-ranges': 'bytes', 'content-encoding': 'br', 'vary': 'Accept-Encoding', 'content-length': '1354', 'date': 'Sat, 27 May 2023 06:02:05 GMT', 'server': 'LiteSpeed', 'x-cache-status': '""', 'x-origin-date': '""', 'x-ua-device': '""', 'alt-svc': 'h3=":443"; ma=2592000, h3-29=":443"; ma=2592000, h3-Q050=":443"; ma=2592000, h3-Q046=":443"; ma=2592000, h3-Q043=":443"; ma=2592000, quic=":443"; ma=2592000; v="43,46"'}
    Response text:
    <!DOCTYPE html>
    <html lang="ja">
    <head>
    <meta charset="EUC-JP" />
    <title>403 Forbidden</title>
    <meta name="copyright" content="Copyright XSERVER Inc.">
    <meta name="robots" content="INDEX,FOLLOW" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0">
    <style type="text/css">
    * {
        margin: 0;
        padding: 0;
    }
    img {
        border: 0;
    }
    ul {
        padding-left: 2em;
    }
    html {
        overflow-y: scroll;
        background: #3b79b7;
    }
    body {
        font-family: "�ᥤ�ꥪ", Meiryo, "�ͣ� �Х����å�", "MS PGothic", "�ҥ饮�γѥ� Pro W3", "Hiragino Kaku Gothic Pro", sans-serif;
        margin: 0;
        line-height: 1.4;
        font-size: 75%;
        text-align: center;
        color: white;
    }
    h1 {
        font-size: 24px;
        font-weight: bold;
    }
    h1 {
        font-weight: bold;
        line-height: 1;
        padding-bottom: 20px;
        font-family: Helvetica, sans-serif;
    }
    h2 {
        text-align: center;
        font-weight: bold;
        font-size: 27px;
    }
    p {
        text-align: center;
        font-size: 14px;
        margin: 0;
        padding: 0;
        color: white;
    }
    .explain {
        border-top: 1px solid #fff;
        border-bottom: 1px solid #fff;
        line-height: 1.5;
        margin: 30px auto;
        padding: 17px;
    }
    #cause {
        text-align: left;
    }
    #cause li {
        color: #666;
    }
    h3 {
        letter-spacing: 1px;
        font-weight: bold;
        padding: 0;
    }
    #white_box {
        margin: 15px auto 0;
        background-color: white;
    }
    
    /* ====================
    
      ���ޡ��ȥե���
    
    ======================= */
    @media only screen and (min-width: 0) and (max-width: 767px) {
    	#base {
    		padding: 30px 10px;
    	}
    	h1 {
    		font-size: 26px;
    	}
    	h1 span {
    		font-size: 60px;
    	}
    	h2 {
    		font-size: 16px;
    	}
    	.explain {
    		font-size: 14px;
    	}
    	h3 {
    		margin-top: 45px;
    		font-size: 16px;
    	}
    	#cause {
    		padding: 20px;
    		font-size: 12px;
    	}
    }
    
    /* ====================
    
       �ѥ���������֥�å�
    
    ======================= */
    
    @media only screen and (min-width: 768px) {
    	#base {
    		margin-top: 80px;
    	}
    	h1 {
    		font-size: 50px;
    	}
    	h1 span {
    		font-size: 110px;
    	}
    	.explain {
    		font-size: 16px;
    		width: 660px;
    	}
    	#white_box {
    		width: 680px;
    		margin-bottom: 50px;
    	}
    	h3 {
    		font-size: 20px;
    		margin-top: 80px;
    	}
    	#cause {
    		padding: 30px;
    		font-size: 14px;
    	}
    }
    </style>
    </head>
    
    <body>
    <div id="base">
        <h1><span>403</span><br />
            Forbidden</h1>
        <h2>�����������褦�Ȥ����ڡ�����ɽ���Ǥ��ޤ���Ǥ�����</h2>
        <p class="explain">���Υ��顼�ϡ�ɽ������ڡ����ؤΥ����������Ĥ��ʤ��ä����Ȥ��̣���ޤ���</p>
        <h3>�ʲ��Τ褦�ʸ������ͤ����ޤ���</h3>
        <div id="white_box">
            <div id="cause">
                <ul>
                    <li>�������������Ĥ���Ƥ��ʤ��ʥѡ��ߥå�������ˤ�äƶػߤ���Ƥ���ˡ�</li>
                    <li>�ǥե���ȥɥ�����ȡ�index.html, index.htm ���ˤ�¸�ߤ��ʤ���</li>
                </ul>
            </div>
        </div>
        <!--//base--></div>
    </body>
    </html>
    
    ​
    --------------------------------------------
    Thread Starter yasu7

    (@yasu7)

    Hi @amieiro

    Thank you for your help.
    When I ran python3 test.py -v at the command prompt, the following result was displayed.
    
    C:\●●●\●●●>python3 wp1.py -v
    <!DOCTYPE html>
    <html lang="ja">
    <head>
    <meta charset="EUC-JP" />
    <title>403 Forbidden</title>
    <meta name="copyright" content="Copyright XSERVER Inc.">
    <meta name="robots" content="INDEX,FOLLOW" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0">
    <style type="text/css">
    * {
        margin: 0;
        padding: 0;
    }
    img {
        border: 0;
    }
    ul {
        padding-left: 2em;
    }
    html {
        overflow-y: scroll;
        background: #3b79b7;
    }
    body {
        font-family: "�ᥤ�ꥪ", Meiryo, "�ͣ� �Х����å�", "MS PGothic", "�ҥ饮�γѥ� Pro W3", "Hiragino Kaku Gothic Pro", sans-serif;
        margin: 0;
        line-height: 1.4;
        font-size: 75%;
        text-align: center;
        color: white;
    }
    h1 {
        font-size: 24px;
        font-weight: bold;
    }
    h1 {
        font-weight: bold;
        line-height: 1;
        padding-bottom: 20px;
        font-family: Helvetica, sans-serif;
    }
    h2 {
        text-align: center;
        font-weight: bold;
        font-size: 27px;
    }
    p {
        text-align: center;
        font-size: 14px;
        margin: 0;
        padding: 0;
        color: white;
    }
    .explain {
        border-top: 1px solid #fff;
        border-bottom: 1px solid #fff;
        line-height: 1.5;
        margin: 30px auto;
        padding: 17px;
    }
    #cause {
        text-align: left;
    }
    #cause li {
        color: #666;
    }
    h3 {
        letter-spacing: 1px;
        font-weight: bold;
        padding: 0;
    }
    #white_box {
        margin: 15px auto 0;
        background-color: white;
    }
    
    /* ====================
    
      ���ޡ��ȥե���
    
    ======================= */
    @media only screen and (min-width: 0) and (max-width: 767px) {
            #base {
                    padding: 30px 10px;
            }
            h1 {
                    font-size: 26px;
            }
            h1 span {
                    font-size: 60px;
            }
            h2 {
                    font-size: 16px;
            }
            .explain {
                    font-size: 14px;
            }
            h3 {
                    margin-top: 45px;
                    font-size: 16px;
            }
            #cause {
                    padding: 20px;
                    font-size: 12px;
            }
    }
    
    /* ====================
    
       �ѥ���������֥�å�
    
    ======================= */
    
    @media only screen and (min-width: 768px) {
            #base {
                    margin-top: 80px;
            }
            h1 {
                    font-size: 50px;
            }
            h1 span {
                    font-size: 110px;
            }
            .explain {
                    font-size: 16px;
                    width: 660px;
            }
            #white_box {
                    width: 680px;
                    margin-bottom: 50px;
            }
            h3 {
                    font-size: 20px;
                    margin-top: 80px;
            }
            #cause {
                    padding: 30px;
                    font-size: 14px;
            }
    }
    </style>
    </head>
    
    <body>
    <div id="base">
        <h1><span>403</span><br />
            Forbidden</h1>
        <h2>�����������褦�Ȥ����ڡ�����ɽ���Ǥ��ޤ���Ǥ�����</h2>
        <p class="explain">���Υ��顼�ϡ�ɽ������ڡ����ؤΥ����������Ĥ��ʤ��ä����Ȥ��̣���ޤ ���</p>
        <h3>�ʲ��Τ褦�ʸ������ͤ����ޤ���</h3>
        <div id="white_box">
            <div id="cause">
                <ul>
                    <li>�������������Ĥ���Ƥ��ʤ��ʥѡ��ߥå�������ˤ�äƶػߤ���Ƥ���ˡ�</li>
                    <li>�ǥե���ȥɥ�����ȡ�index.html, index.htm ���ˤ�¸�ߤ��ʤ���</li>
                </ul>
            </div>
        </div>
        <!--//base--></div>
    </body>
    </html>
    
    
    ※※※※※※※※ wp1.py ※※※※※※※※※※※※※
    import requests
    
    url = 'https://YYYYYYY.wp.xdomain.jp/wp-json/wp/v2/posts/'
    headers = {'Content-Type': 'application/json'}
    auth = ('YYYYYYY', 'XXXX XXXX XXXX XXXX XXXX XXXX')
    data = {
        'title': 'Test title',
        'content': 'Test content',
        'status': 'publish',
        'slug': 'test-title'
    }
    
    response = requests.post(url, headers=headers, auth=auth, json=data)
    print(response.text)
    
    ※※※※※※※※※※※※※※※※※※※※※
    Thread Starter yasu7

    (@yasu7)

    Hi @amieiro

    Thank you for your help.
    Here's what I see running in Jupyter Notebook(the whole error):
    
    
    ------------------------------------------------------------------------------------------------------------------------------
    <!DOCTYPE html>
    <html lang="ja">
    <head>
    <meta charset="EUC-JP" />
    <title>403 Forbidden</title>
    <meta name="copyright" content="Copyright XSERVER Inc.">
    <meta name="robots" content="INDEX,FOLLOW" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0">
    <style type="text/css">
    * {
        margin: 0;
        padding: 0;
    }
    img {
        border: 0;
    }
    ul {
        padding-left: 2em;
    }
    html {
        overflow-y: scroll;
        background: #3b79b7;
    }
    body {
        font-family: "�ᥤ�ꥪ", Meiryo, "�ͣ� �Х����å�", "MS PGothic", "�ҥ饮�γѥ� Pro W3", "Hiragino Kaku Gothic Pro", sans-serif;
        margin: 0;
        line-height: 1.4;
        font-size: 75%;
        text-align: center;
        color: white;
    }
    h1 {
        font-size: 24px;
        font-weight: bold;
    }
    h1 {
        font-weight: bold;
        line-height: 1;
        padding-bottom: 20px;
        font-family: Helvetica, sans-serif;
    }
    h2 {
        text-align: center;
        font-weight: bold;
        font-size: 27px;
    }
    p {
        text-align: center;
        font-size: 14px;
        margin: 0;
        padding: 0;
        color: white;
    }
    .explain {
        border-top: 1px solid #fff;
        border-bottom: 1px solid #fff;
        line-height: 1.5;
        margin: 30px auto;
        padding: 17px;
    }
    #cause {
        text-align: left;
    }
    #cause li {
        color: #666;
    }
    h3 {
        letter-spacing: 1px;
        font-weight: bold;
        padding: 0;
    }
    #white_box {
        margin: 15px auto 0;
        background-color: white;
    }
    
    /* ====================
    
      ���ޡ��ȥե���
    
    ======================= */
    @media only screen and (min-width: 0) and (max-width: 767px) {
    	#base {
    		padding: 30px 10px;
    	}
    	h1 {
    		font-size: 26px;
    	}
    	h1 span {
    		font-size: 60px;
    	}
    	h2 {
    		font-size: 16px;
    	}
    	.explain {
    		font-size: 14px;
    	}
    	h3 {
    		margin-top: 45px;
    		font-size: 16px;
    	}
    	#cause {
    		padding: 20px;
    		font-size: 12px;
    	}
    }
    
    /* ====================
    
       �ѥ���������֥�å�
    
    ======================= */
    
    @media only screen and (min-width: 768px) {
    	#base {
    		margin-top: 80px;
    	}
    	h1 {
    		font-size: 50px;
    	}
    	h1 span {
    		font-size: 110px;
    	}
    	.explain {
    		font-size: 16px;
    		width: 660px;
    	}
    	#white_box {
    		width: 680px;
    		margin-bottom: 50px;
    	}
    	h3 {
    		font-size: 20px;
    		margin-top: 80px;
    	}
    	#cause {
    		padding: 30px;
    		font-size: 14px;
    	}
    }
    </style>
    </head>
    
    <body>
    <div id="base">
        <h1><span>403</span><br />
            Forbidden</h1>
        <h2>�����������褦�Ȥ����ڡ�����ɽ���Ǥ��ޤ���Ǥ�����</h2>
        <p class="explain">���Υ��顼�ϡ�ɽ������ڡ����ؤΥ����������Ĥ��ʤ��ä����Ȥ��̣���ޤ���</p>
        <h3>�ʲ��Τ褦�ʸ������ͤ����ޤ���</h3>
        <div id="white_box">
            <div id="cause">
                <ul>
                    <li>�������������Ĥ���Ƥ��ʤ��ʥѡ��ߥå�������ˤ�äƶػߤ���Ƥ���ˡ�</li>
                    <li>�ǥե���ȥɥ�����ȡ�index.html, index.htm ���ˤ�¸�ߤ��ʤ���</li>
                </ul>
            </div>
        </div>
        <!--//base--></div>
    </body>
    </html>
    
    ​----------------------------------------------------------------------------------------------------------
    
    Thread Starter yasu7

    (@yasu7)

    @amieiro
    Thank you for your advice! The curl command was able to post the article successfully! However, the python program tried several times with my parameters and got error code 403. I have already confirmed the items listed in [Confirmed items] below, but if you have any other ideas about what to do to resolve the error, I am very sorry, but could you please let me know?

    [Confirmed items]
    ・Application password is already set
    ・Restrictions on access to “WordPress REST API” from foreign IP addresses have been disabled
    ・Confirmed that the endpoint URL is correct
    ・Confirmed that I’m using the credentials of a user with WordPress administrator privileges

Viewing 5 replies - 1 through 5 (of 5 total)