์ƒˆ์†Œ์‹

๐Ÿ’ป Programming/์—๋Ÿฌ ๋ชจ์Œ์ง‘

urllib3 request() ์‚ฌ์šฉ ์‹œ Mod_security ์—๋Ÿฌ

2023. 3. 3. 19:19

  • -

urllib3.PoolManager()๋ฅผ ์‚ฌ์šฉํ•ด์„œ url์—์„œ zip ํŒŒ์ผ์„ ๋‹ค์šด๋ฐ›์œผ๋ ค ํ–ˆ๋Š”๋ฐ

๋‹ค์šด๋ฐ›์•„์ง„ zip ํŒŒ์ผ ์•ˆ์— ์—๋Ÿฌ ๋ฉ”์„ธ์ง€๋งŒ ๋“ค์–ด์žˆ๊ณ  ํŒŒ์ผ์ด ์ œ๋Œ€๋กœ ๋‹ค์šด๋ฐ›์•„์ง€์ง€ ์•Š์•˜๋‹ค.

 

 

 

์—๋Ÿฌ ๋ฉ”์„ธ์ง€

 

Not Acceptable! An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.

 

 

 

 

ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

 

user-agent ์ถ”๊ฐ€

 

 

# http = urllib3.PoolManager() user_agent = {'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'} with http.request('GET', url, preload_content=False, headers=user_agent) as r, open(zipfilename, 'wb') as out_file: shutil.copyfileobj(r, out_file)

 

  • user-agent์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ์ž‘์„ฑํ•œ ๋’ค, request()์— headers=user_agent๋กœ ์ถ”๊ฐ€
  • user-agent
    • HTTP ์š”์ฒญ์„ ๋ณด๋‚ด๋Š” ๋””๋ฐ”์ด์Šค์™€ ๋ธŒ๋ผ์šฐ์ € ๋“ฑ ์‚ฌ์šฉ์ž ์†Œํ”„ํŠธ์›จ์–ด์˜ ์‹๋ณ„ ์ •๋ณด๋ฅผ ๋‹ด๊ณ  ์žˆ๋Š” request header์˜ ํ•œ ์ข…๋ฅ˜
    • ๋ณดํ†ต HTTP ์š”์ฒญ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ ์š”์ฒญ์„ ๋ณด๋‚ธ ์‚ฌ์šฉ์ž ํ™˜๊ฒฝ์„ ์•Œ์•„๋ณด๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ
    • ์ž„์˜๋กœ ์ˆ˜์ •๋  ์ˆ˜ ์—†๋Š” ๊ฐ’

 

 

์œ„์˜ ์ฝ”๋“œ์— ์ž‘์„ฑํ•œ user-agent ๊ฐ’์€ ์•„๋ž˜ ๋ธ”๋กœ๊ทธ์—์„œ Chrome์˜ ์˜ˆ์‹œ๋กœ ๋‚˜์˜จ ๊ฐ’์„ ๊ฐ€์ ธ์™€์„œ ์‚ฌ์šฉํ–ˆ๋‹ค.

 

user_agent = {'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'}

 

 

https://velog.io/@ggong/User-agent-%EC%A0%95%ED%99%95%ED%95%98%EA%B2%8C-%ED%95%B4%EC%84%9D%ED%95%98%EA%B8%B0

 

User-agent ์ •ํ™•ํ•˜๊ฒŒ ํ•ด์„ํ•˜๊ธฐ

user agent๋Š” HTTP ์š”์ฒญ์„ ๋ณด๋‚ด๋Š” ๋””๋ฐ”์ด์Šค์™€ ๋ธŒ๋ผ์šฐ์ € ๋“ฑ ์‚ฌ์šฉ์ž ์†Œํ”„ํŠธ์›จ์–ด์˜ ์‹๋ณ„ ์ •๋ณด๋ฅผ ๋‹ด๊ณ  ์žˆ๋Š” request header์˜ ํ•œ ์ข…๋ฅ˜์ด๋‹ค. ์ž„์˜๋กœ ์ˆ˜์ •๋  ์ˆ˜ ์—†๋Š” ๊ฐ’์ด๊ณ , ๋ณดํ†ต HTTP ์š”์ฒญ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ

velog.io

 

 

 

 

 

 

https://stackoverflow.com/questions/57387427/i-cant-get-a-response-from-a-get-request-using-urllib3-for-a-particular-url-bu

 

I can't get a response from a GET request using urllib3 for a particular URL, but I can do it with requests and urllib?

I am attempting to access the url 'https://www.nasdaq.com/screening/companies-by-name.aspx?letter=0&exchange=nasdaq&render=download' which downloads a CSV file. When I use urllib3 and send ...

stackoverflow.com

 

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent

 

User-Agent - HTTP | MDN

The User-Agent request header is a characteristic string that lets servers and network peers identify the application, operating system, vendor, and/or version of the requesting user agent.

developer.mozilla.org

 

Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค!