μƒˆμ†Œμ‹

πŸ’» 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

ν¬μŠ€νŒ… μ£Όμ†Œλ₯Ό λ³΅μ‚¬ν–ˆμŠ΅λ‹ˆλ‹€

이 글이 도움이 λ˜μ—ˆλ‹€λ©΄ 곡감 λΆ€νƒλ“œλ¦½λ‹ˆλ‹€!